943,568 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 16187
  • C# RSS
Mar 6th, 2006
0

Custom Control Button with different regions

Expand Post »
Hi,

Im trying to create a button that will perform different functions depending on what part of the button you click. The button will be a diamond shape with six different regions on it that will perform different actions (play, pause, volume up/down etc). Does anyone know any good sites where I can get help with this as Im not sure where to start.

Thanks.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mickeyfitzray is offline Offline
9 posts
since Feb 2006
Mar 7th, 2006
0

Re: Custom Control Button with different regions

I suggest you create a control with 4 seperate buttons for each function, but then draw them together so it looks like one button.

below is code that makes a button look like a circle. this should be the onPaint function for the button. it shouldnt be to difficult to edit this to work for you


C# Syntax (Toggle Plain Text)
  1. // This method will change the square button to a circular button by
  2. // creating a new circle-shaped GraphicsPath object and setting it
  3. // to the RoundButton objects region.
  4. private void roundButton_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
  5. {
  6.  
  7. System.Windows.Forms.Button tButton = (System.Windows.Forms.Button)sender;
  8.  
  9.  
  10. System.Drawing.Drawing2D.GraphicsPath buttonPath =
  11. new System.Drawing.Drawing2D.GraphicsPath();
  12.  
  13.  
  14. // Set a new rectangle to the same size as the button's
  15. // ClientRectangle property.
  16. System.Drawing.Rectangle newRectangle = tButton.ClientRectangle;
  17.  
  18. // Decrease the size of the rectangle.
  19. newRectangle.Inflate(-10, -10);
  20.  
  21. // Draw the button's border.
  22. e.Graphics.DrawEllipse(System.Drawing.Pens.Black, newRectangle);
  23.  
  24. // Increase the size of the rectangle to include the border.
  25. newRectangle.Inflate( 1, 1);
  26.  
  27.  
  28. // Create a circle within the new rectangle.
  29. buttonPath.AddEllipse(newRectangle);
  30.  
  31. // Set the button's Region property to the newly created
  32. // circle region.
  33. tButton.Region = new System.Drawing.Region(buttonPath);
  34.  
  35. }
Reputation Points: 23
Solved Threads: 16
Posting Whiz in Training
plazmo is offline Offline
206 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Help with another key. (Almost done)!
Next Thread in C# Forum Timeline: Datagrid





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC