View Single Post
Join Date: Aug 2005
Posts: 206
Reputation: plazmo is an unknown quantity at this point 
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: Custom Control Button with different regions

 
0
  #2
Mar 7th, 2006
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


  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. }
Reply With Quote