473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Line wont show up

When I create taskbox on the form the line beside the box wont show up.
it show up untill I have MouseEnter event occur.
Also when I have 2 taskbox on the form it does draw the line around the label
however the line wont draw when i have 1 taskbox move away from another taskbox. The line is gone at last sec when taskbox move away.

could someone please tell me where does I made mistake and how to fix it
thank you
Below is the code.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Windows.Forms;
  5. using System.Drawing;
  6.  
  7. namespace Task
  8. {
  9.     public class TaskBox: Label
  10.     {
  11.         private bool m_IsPressed;
  12.         private int curDifX,curDifY;
  13.         private const int STEPBOX_WIDTH = 105;
  14.         private const int STEPBOX_HEIGHT = 25;
  15.  
  16.         public event MouseRightKeyPressHandler MouseRightKeyPress;
  17.         public delegate void MouseRightKeyPressHandler(object sender, MouseEventArgs e);
  18.  
  19.         public event DeleteTaskHandler DeleteTask;
  20.         public delegate void DeleteTaskHandler(object sender);
  21.  
  22.  
  23.         public TaskBox(string name) {
  24.  
  25.             this.Text = name;
  26.             this.TextAlign = ContentAlignment.MiddleCenter;
  27.             this.BorderStyle = BorderStyle.None;
  28.             this.Size = new Size(STEPBOX_WIDTH, STEPBOX_HEIGHT);
  29.             this.MouseDown += new System.Windows.Forms.MouseEventHandler(this_MouseDown);
  30.             this.MouseMove += new System.Windows.Forms.MouseEventHandler(this_MouseMove);
  31.             this.KeyUp += new System.Windows.Forms.KeyEventHandler(this_KeyUp);
  32.             this.MouseUp += new System.Windows.Forms.MouseEventHandler(this_MouseUp);
  33.             this.MouseLeave += new EventHandler(this_MouseLeave);
  34.             this.MouseEnter += new EventHandler(this_MouseEnter);
  35.             this.BackColor = Color.FromKnownColor(KnownColor.Control);
  36.             this.LostFocus+=new EventHandler(this_LostFocus);
  37.             this.Paint+=new PaintEventHandler(TaskBox_Paint);
  38.  
  39.        }
  40.  
  41.           private void this_MouseDown(object sender, MouseEventArgs e)
  42.         {
  43.             m_IsPressed = true;
  44.             (sender as TaskBox).Select();
  45.             curDifX = Cursor.Position.X - (sender as Label).Left;
  46.             curDifY = Cursor.Position.Y - (sender as Label).Top;
  47.             (sender as TaskBox).BackColor = Color.Teal;
  48.             if (e.Button == MouseButtons.Right)
  49.             {
  50.                 if (MouseRightKeyPress != null)
  51.                 {
  52.  
  53.                     MouseRightKeyPress(this, e);
  54.                 }
  55.             }
  56.  
  57.         }
  58.  
  59.         private void this_MouseMove(object sender, MouseEventArgs e)
  60.         {
  61.             if (m_IsPressed == true)
  62.             {
  63.                 if (Cursor.Position.X - curDifX < 0)
  64.                 {
  65.                     (sender as TaskBox).Left = 0;
  66.                 }
  67.                 else
  68.                 {
  69.                     (sender as TaskBox).Left = Cursor.Position.X - curDifX;
  70.                 }
  71.  
  72.                 if (Cursor.Position.Y - curDifY < 0)
  73.                 {
  74.                     (sender as TaskBox).Top = 0;
  75.  
  76.                 }
  77.                 else
  78.                 {
  79.                     (sender as TaskBox).Top = Cursor.Position.Y - curDifY;
  80.                 }
  81.  
  82.                 (sender as TaskBox).BringToFront();
  83.  
  84.             }
  85.         }
  86.  
  87.         private void this_MouseUp(object sender, MouseEventArgs e)
  88.         {
  89.             (sender as TaskBox).BackColor = Color.Teal;
  90.             m_IsPressed = false;
  91.  
  92.         }
  93.  
  94.          private void this_MouseEnter(object sender, EventArgs e)
  95.         {
  96.             Graphics g = (sender as TaskBox).CreateGraphics();
  97.             g.DrawRectangle(Pens.Red, 0, 0, STEPBOX_WIDTH-1, STEPBOX_HEIGHT-1);
  98.         }
  99.         private void this_MouseLeave(object sender, EventArgs e)
  100.         {
  101.             Graphics g = (sender as TaskBox).CreateGraphics();
  102.             g.DrawRectangle(Pens.Black, 0, 0, STEPBOX_WIDTH-1, STEPBOX_HEIGHT-1);
  103.         }
  104.  
  105.         private void this_KeyUp(object sender, KeyEventArgs e)
  106.         {
  107.             if (e.KeyData == Keys.Delete)
  108.             {
  109.                 DeleteTask(this);
  110.             }
  111.         }
  112.  
  113.  
  114.         public void TaskBox_Paint(Object sender,PaintEventArgs e)
  115.         {
  116.             Graphics g = (sender as TaskBox).CreateGraphics();
  117.  
  118.  
  119.             if (m_IsPressed)
  120.             {
  121.                 g.DrawRectangle(Pens.Red, 0, 0, STEPBOX_WIDTH - 1, STEPBOX_HEIGHT - 1);
  122.             }
  123.             else
  124.             {
  125.                 g.DrawRectangle(Pens.Black, 0, 0, STEPBOX_WIDTH - 1, STEPBOX_HEIGHT - 1);
  126.             }
  127.  
  128.         }
  129.  
  130.         private void this_LostFocus(object sender, EventArgs e)
  131.         {
  132.  
  133.             (sender as TaskBox).BackColor = Color.FromKnownColor(KnownColor.Control);
  134.         }
  135.  
  136.     }
  137. }
Jan 17 '08 #1
0 1342

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Steven Stern | last post by:
I have a script that will be run as a cron task every night but occasionally will run when request by the browser. When run by the browser, I want it to output results to the screen. What's an...
5
by: Catherine | last post by:
I am having a problem viewing asp pages on iis version 5.1 xp pro. HTML pages are viewable on http://localhost but .asp pages are not. I have created a test program called timetest.asp with the...
0
by: Bob Ranck | last post by:
More on earlier thread "Base Form that wont go away" Response to Chris Dunaway dunawayc@lunchmeatsbcglobal.net Here is the code snippet that calls the working form in the MDI. I actually...
12
by: Ali | last post by:
I have the following web page with a script in it. <html> <head> <title>Make Your Own Objects test</title> <script>
1
by: eewwttww | last post by:
how to show the "txt code" that the WebBrowser wont to save when he wont to save html+pictures with the "dialogbox" - before saving. this is the code to open the save "dialogbox" ...
1
by: Diz | last post by:
Hi, Can anybody tell me why my php script wont run properly unless i put it in a page all on its own? Is it antisocial? Does it want to be alone? I have put it in a page with background and links to...
3
by: Arthur Dent | last post by:
Hello All,.. I have some settings stored in the project settings which show up under My.Settings. ... All works fine. Now, I wanted to change the value of one of these settings, so I went...
0
by: watashi | last post by:
Hello, This is on socket. i m using tcpclient and tcplistener task is when the "Active " button is pressed according to user choice tool should work as server or client. when "Inactive"...
3
by: Sean425 | last post by:
import java.util.*; class variables { public static void main(String args) { Scanner input = new Scanner(System.in); String op; int numberOne, numberTwo, result = 0;
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.