Is there a way to make a checkbox (button style) that is triangular
shaped? 10 3430
Jess,
You make mu curious, why?
Cor
<Je**@aol.comschreef in bericht
news:ci********************************@4ax.com...
Is there a way to make a checkbox (button style) that is triangular
shaped?
I wand to create a diamond shape button that has consists of a left
right top and button segment (4 triangles) that toggles.
On Sat, 27 Jan 2007 20:36:09 +0100, "Cor Ligthert [MVP]"
<no************@planet.nlwrote:
>Jess,
You make mu curious, why?
Cor
<Je**@aol.comschreef in bericht news:ci********************************@4ax.com.. .
>Is there a way to make a checkbox (button style) that is triangular shaped?
So does each segment toggle (i.e. four on/off boxes on each control)?
If so here's one method you could use. You could just inherit the
checkbox class and add a property that holds which position the
triangle is in (left, right, top, or bottom). Then, in it's overriden
paint method reference that property and draw the appropriate image
based on the value it returns (I would use an enum and a switch
statement) Then add four of this custom check box to your user
control, set the new position property, and drag them to where you
need them on the control. All that would be left is to create any
properties you might need for the control.
I hope that made since (it's getting pretty late here :-) )
Thanks,
Seth Rowe
On Jan 27, 3:33 pm, J...@aol.com wrote:
I wand to create a diamond shape button that has consists of a left
right top and button segment (4 triangles) that toggles.
On Sat, 27 Jan 2007 20:36:09 +0100, "Cor Ligthert [MVP]"
<notmyfirstn...@planet.nlwrote:
Jess,
You make mu curious, why?
Cor
<J...@aol.comschreef in bericht
news:ci********************************@4ax.com...
Is there a way to make a checkbox (button style) that is triangular
shaped?
I had tried this (decided I wanted a pie instead of a triangle) But
the problem is that although it displays the pie you still see the
outline of the square button. This is the code for 1 of the 4 buttons
For the Class
Public Class NewCheckBox2
Inherits CheckBox
Private CenterSquareColor As Color = _
Color.Red
Private CenterSquareColor2 As Color = _
Color.Blue
Protected Overrides Sub OnPaint( _
ByVal pevent As System.Windows.Forms.PaintEventArgs)
Dim CenterSquare As New Rectangle(-15, -40, 90, 90)
Me.FlatStyle = Windows.Forms.FlatStyle.Flat
'Me.Bounds
MyBase.OnPaint(pevent)
If Me.Checked Then
pevent.Graphics.FillPie(New SolidBrush(CenterSquareColor),
CenterSquare, 45, 90)
Else
pevent.Graphics.FillPie(New
SolidBrush(CenterSquareColor2), CenterSquare, Dim1, Dim2)
End If
End Sub
End Class
For the Form
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim MyCheckBox2 As New NewCheckBox2
With MyCheckBox2
.Text = "Custom Colored Check Box"
.Left = 125 ' OldCheckBox.Left
.Top = 100 ' OldCheckBox.Top + OldCheckBox.Height
.Size = New Size(60, 60) ' OldCheckBox.Size
.Appearance = Appearance.Button
.BackColor = Color.Transparent
.FlatStyle = FlatStyle.Flat
.ForeColor = Color.Transparent
End With
Controls.Add(MyCheckBox2)
End Sub
End Class
On 27 Jan 2007 16:47:01 -0800, "rowe_newsgroups"
<ro********@yahoo.comwrote:
>So does each segment toggle (i.e. four on/off boxes on each control)?
If so here's one method you could use. You could just inherit the checkbox class and add a property that holds which position the triangle is in (left, right, top, or bottom). Then, in it's overriden paint method reference that property and draw the appropriate image based on the value it returns (I would use an enum and a switch statement) Then add four of this custom check box to your user control, set the new position property, and drag them to where you need them on the control. All that would be left is to create any properties you might need for the control.
I hope that made since (it's getting pretty late here :-) )
Thanks,
Seth Rowe
On Jan 27, 3:33 pm, J...@aol.com wrote:
>I wand to create a diamond shape button that has consists of a left right top and button segment (4 triangles) that toggles.
On Sat, 27 Jan 2007 20:36:09 +0100, "Cor Ligthert [MVP]"
<notmyfirstn...@planet.nlwrote:
>Jess,
>You make mu curious, why?
>Cor
><J...@aol.comschreef in bericht news:ci********************************@4ax.com.. . Is there a way to make a checkbox (button style) that is triangular shaped?
Jess,
It absolute not my favorite sport, but to add something to Seth.
Have a look at Region http://msdn2.microsoft.com/en-us/lib...ol.region.aspx
As well think about radiobuttons inside a groupbox, they have in my idea
more the behaviour you want and will in my idea even look nicer.
Cor
<Je**@aol.comschreef in bericht
news:u5********************************@4ax.com...
>I had tried this (decided I wanted a pie instead of a triangle) But
the problem is that although it displays the pie you still see the
outline of the square button. This is the code for 1 of the 4 buttons
For the Class
Public Class NewCheckBox2
Inherits CheckBox
Private CenterSquareColor As Color = _
Color.Red
Private CenterSquareColor2 As Color = _
Color.Blue
Protected Overrides Sub OnPaint( _
ByVal pevent As System.Windows.Forms.PaintEventArgs)
Dim CenterSquare As New Rectangle(-15, -40, 90, 90)
Me.FlatStyle = Windows.Forms.FlatStyle.Flat
'Me.Bounds
MyBase.OnPaint(pevent)
If Me.Checked Then
pevent.Graphics.FillPie(New SolidBrush(CenterSquareColor),
CenterSquare, 45, 90)
Else
pevent.Graphics.FillPie(New
SolidBrush(CenterSquareColor2), CenterSquare, Dim1, Dim2)
End If
End Sub
End Class
For the Form
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim MyCheckBox2 As New NewCheckBox2
With MyCheckBox2
.Text = "Custom Colored Check Box"
.Left = 125 ' OldCheckBox.Left
.Top = 100 ' OldCheckBox.Top + OldCheckBox.Height
.Size = New Size(60, 60) ' OldCheckBox.Size
.Appearance = Appearance.Button
.BackColor = Color.Transparent
.FlatStyle = FlatStyle.Flat
.ForeColor = Color.Transparent
End With
Controls.Add(MyCheckBox2)
End Sub
End Class
On 27 Jan 2007 16:47:01 -0800, "rowe_newsgroups"
<ro********@yahoo.comwrote:
>>So does each segment toggle (i.e. four on/off boxes on each control)?
If so here's one method you could use. You could just inherit the checkbox class and add a property that holds which position the triangle is in (left, right, top, or bottom). Then, in it's overriden paint method reference that property and draw the appropriate image based on the value it returns (I would use an enum and a switch statement) Then add four of this custom check box to your user control, set the new position property, and drag them to where you need them on the control. All that would be left is to create any properties you might need for the control.
I hope that made since (it's getting pretty late here :-) )
Thanks,
Seth Rowe
On Jan 27, 3:33 pm, J...@aol.com wrote:
>>I wand to create a diamond shape button that has consists of a left right top and button segment (4 triangles) that toggles.
On Sat, 27 Jan 2007 20:36:09 +0100, "Cor Ligthert [MVP]"
<notmyfirstn...@planet.nlwrote: Jess,
You make mu curious, why?
Cor
<J...@aol.comschreef in bericht news:ci********************************@4ax.com. .. Is there a way to make a checkbox (button style) that is triangular shaped?
This sounds like a custom control would be better suited to the task.
I have outlined a very basic control below which you can expand upon to give
you exactly what you want.
For instance, you may like to add a Slices property to give you a collection
of PieSlices instead of having a fixed array of 4 PieSlices.
\\\
Public Class CheckPie
Inherits System.Windows.Forms.UserControl
Protected Overrides ReadOnly Property DefaultSize() As Size
Get
Return New Size(48, 48)
End Get
End Property
Private Slices() As PieSlice
Private Class PieSlice
Public Path As New Drawing2D.GraphicsPath
Public Checked As Boolean
Public Sub New()
Me.Path = New Drawing2D.GraphicsPath
End Sub
End Class
Public Sub New()
MyBase.New()
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Slices = New PieSlice() {New PieSlice, New PieSlice, _
New PieSlice, New PieSlice}
Me.OnResize(EventArgs.Empty)
End Sub
Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
MyBase.OnResize(e)
Dim r As Rectangle = Me.ClientRectangle
r.Width -= 1
r.Height -= 1
For id As Int32 = 0 To 3
Slices(id).Path.Reset()
Slices(id).Path.AddPie(r, 45 + (id * 90), 90)
Next
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
If Slices.Length = 0 Then Return
For Each slice As PieSlice In Slices
If slice.Checked Then
e.Graphics.FillPath(Brushes.Red, slice.Path)
Else
e.Graphics.FillPath(Brushes.Blue, slice.Path)
End If
e.Graphics.DrawPath(Pens.Gray, slice.Path)
Next
End Sub
Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
MyBase.OnClick(e)
For Each slice As PieSlice In Slices
Dim pt As Point = Me.PointToClient(Me.MousePosition)
If slice.Path.IsVisible(pt.X, pt.Y) Then
slice.Checked = Not slice.Checked
Me.Invalidate(New Region(slice.Path))
End If
Next
End Sub
End Class
///
--
Mick Doherty http://dotnetrix.co.uk/nothing.html
<Je**@aol.comwrote in message
news:u5********************************@4ax.com...
>I had tried this (decided I wanted a pie instead of a triangle) But
the problem is that although it displays the pie you still see the
outline of the square button. This is the code for 1 of the 4 buttons
For the Class
Public Class NewCheckBox2
Inherits CheckBox
Private CenterSquareColor As Color = _
Color.Red
Private CenterSquareColor2 As Color = _
Color.Blue
Protected Overrides Sub OnPaint( _
ByVal pevent As System.Windows.Forms.PaintEventArgs)
Dim CenterSquare As New Rectangle(-15, -40, 90, 90)
Me.FlatStyle = Windows.Forms.FlatStyle.Flat
'Me.Bounds
MyBase.OnPaint(pevent)
If Me.Checked Then
pevent.Graphics.FillPie(New SolidBrush(CenterSquareColor),
CenterSquare, 45, 90)
Else
pevent.Graphics.FillPie(New
SolidBrush(CenterSquareColor2), CenterSquare, Dim1, Dim2)
End If
End Sub
End Class
For the Form
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim MyCheckBox2 As New NewCheckBox2
With MyCheckBox2
.Text = "Custom Colored Check Box"
.Left = 125 ' OldCheckBox.Left
.Top = 100 ' OldCheckBox.Top + OldCheckBox.Height
.Size = New Size(60, 60) ' OldCheckBox.Size
.Appearance = Appearance.Button
.BackColor = Color.Transparent
.FlatStyle = FlatStyle.Flat
.ForeColor = Color.Transparent
End With
Controls.Add(MyCheckBox2)
End Sub
End Class
On 27 Jan 2007 16:47:01 -0800, "rowe_newsgroups"
<ro********@yahoo.comwrote:
>>So does each segment toggle (i.e. four on/off boxes on each control)?
If so here's one method you could use. You could just inherit the checkbox class and add a property that holds which position the triangle is in (left, right, top, or bottom). Then, in it's overriden paint method reference that property and draw the appropriate image based on the value it returns (I would use an enum and a switch statement) Then add four of this custom check box to your user control, set the new position property, and drag them to where you need them on the control. All that would be left is to create any properties you might need for the control.
I hope that made since (it's getting pretty late here :-) )
Thanks,
Seth Rowe
On Jan 27, 3:33 pm, J...@aol.com wrote:
>>I wand to create a diamond shape button that has consists of a left right top and button segment (4 triangles) that toggles.
On Sat, 27 Jan 2007 20:36:09 +0100, "Cor Ligthert [MVP]"
<notmyfirstn...@planet.nlwrote: Jess,
You make mu curious, why?
Cor
<J...@aol.comschreef in bericht news:ci********************************@4ax.com. .. Is there a way to make a checkbox (button style) that is triangular shaped?
THANX
On Sun, 28 Jan 2007 11:39:49 -0000, "Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]>
wrote:
>This sounds like a custom control would be better suited to the task.
I have outlined a very basic control below which you can expand upon to give you exactly what you want. For instance, you may like to add a Slices property to give you a collection of PieSlices instead of having a fixed array of 4 PieSlices.
\\\ Public Class CheckPie
Inherits System.Windows.Forms.UserControl
Protected Overrides ReadOnly Property DefaultSize() As Size
Get
Return New Size(48, 48)
End Get
End Property
Private Slices() As PieSlice
Private Class PieSlice
Public Path As New Drawing2D.GraphicsPath
Public Checked As Boolean
Public Sub New()
Me.Path = New Drawing2D.GraphicsPath
End Sub
End Class
Public Sub New()
MyBase.New()
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Slices = New PieSlice() {New PieSlice, New PieSlice, _
New PieSlice, New PieSlice}
Me.OnResize(EventArgs.Empty)
End Sub
Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
MyBase.OnResize(e)
Dim r As Rectangle = Me.ClientRectangle
r.Width -= 1
r.Height -= 1
For id As Int32 = 0 To 3
Slices(id).Path.Reset()
Slices(id).Path.AddPie(r, 45 + (id * 90), 90)
Next
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
If Slices.Length = 0 Then Return
For Each slice As PieSlice In Slices
If slice.Checked Then
e.Graphics.FillPath(Brushes.Red, slice.Path)
Else
e.Graphics.FillPath(Brushes.Blue, slice.Path)
End If
e.Graphics.DrawPath(Pens.Gray, slice.Path)
Next
End Sub
Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
MyBase.OnClick(e)
For Each slice As PieSlice In Slices
Dim pt As Point = Me.PointToClient(Me.MousePosition)
If slice.Path.IsVisible(pt.X, pt.Y) Then
slice.Checked = Not slice.Checked
Me.Invalidate(New Region(slice.Path))
End If
Next
End Sub
End Class ///
Try the code and got the following warning
Public Sub New()' in designer-generated type 'Project1.CheckPie'
should call InitializeComponent method.
Not sure what this means
On Sun, 28 Jan 2007 11:39:49 -0000, "Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]>
wrote:
>This sounds like a custom control would be better suited to the task.
I have outlined a very basic control below which you can expand upon to give you exactly what you want. For instance, you may like to add a Slices property to give you a collection of PieSlices instead of having a fixed array of 4 PieSlices.
\\\ Public Class CheckPie
Inherits System.Windows.Forms.UserControl
Protected Overrides ReadOnly Property DefaultSize() As Size
Get
Return New Size(48, 48)
End Get
End Property
Private Slices() As PieSlice
Private Class PieSlice
Public Path As New Drawing2D.GraphicsPath
Public Checked As Boolean
Public Sub New()
Me.Path = New Drawing2D.GraphicsPath
End Sub
End Class
Public Sub New()
MyBase.New()
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Slices = New PieSlice() {New PieSlice, New PieSlice, _
New PieSlice, New PieSlice}
Me.OnResize(EventArgs.Empty)
End Sub
Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
MyBase.OnResize(e)
Dim r As Rectangle = Me.ClientRectangle
r.Width -= 1
r.Height -= 1
For id As Int32 = 0 To 3
Slices(id).Path.Reset()
Slices(id).Path.AddPie(r, 45 + (id * 90), 90)
Next
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
If Slices.Length = 0 Then Return
For Each slice As PieSlice In Slices
If slice.Checked Then
e.Graphics.FillPath(Brushes.Red, slice.Path)
Else
e.Graphics.FillPath(Brushes.Blue, slice.Path)
End If
e.Graphics.DrawPath(Pens.Gray, slice.Path)
Next
End Sub
Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
MyBase.OnClick(e)
For Each slice As PieSlice In Slices
Dim pt As Point = Me.PointToClient(Me.MousePosition)
If slice.Path.IsVisible(pt.X, pt.Y) Then
slice.Checked = Not slice.Checked
Me.Invalidate(New Region(slice.Path))
End If
Next
End Sub
End Class ///
InitializeComponent() is a method that contains all the designer
generated code that is used for initializing the control. To
demonstrate, create a form and set a few properties and maybe add a
control or two. Then in the solution explorer, click the button at top
that shows everything. Then expand the newly created form's node and
open the Form.Designer.vb file. In that code file should be the
InitializeComponent method, you might have to expand the #Region
sections first in order to find the sub though. In that method you
will see the code that is generated for each change you made in the
designer.
The reason you (normally) need do call the InitializeComponent method
first is that it responsible for instantiating the objects. If you
need to call InitializeComponent but don't, then every time you try to
reference a designer added component you will get a
NullReferenceException, since none of the objects were ever created.
However, if you handle all the instantiation/initialization somewhere
else in your code then you can completely ignore having to use the
InitializeComponent sub. For
compliance to the standards, or to get rid of the warning, you may
just want to write your initialization code in a method called
InitializeComponent. It's completely up to you.
Hope that helps.
Thanks,
Seth Rowe
On Jan 28, 12:44 pm, J...@aol.com wrote:
Try the code and got the following warning
Public Sub New()' in designer-generated type 'Project1.CheckPie'
should call InitializeComponent method.
Not sure what this means
On Sun, 28 Jan 2007 11:39:49 -0000, "Mick Doherty"
<EXCHANGE#W...@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]>
wrote:
This sounds like a custom control would be better suited to the task.
I have outlined a very basic control below which you can expand upon to give
you exactly what you want.
For instance, you may like to add a Slices property to give you a collection
of PieSlices instead of having a fixed array of 4 PieSlices.
\\\
Public Class CheckPie
Inherits System.Windows.Forms.UserControl
Protected Overrides ReadOnly Property DefaultSize() As Size
Get
Return New Size(48, 48)
End Get
End Property
Private Slices() As PieSlice
Private Class PieSlice
Public Path As New Drawing2D.GraphicsPath
Public Checked As Boolean
Public Sub New()
Me.Path = New Drawing2D.GraphicsPath
End Sub
End Class
Public Sub New()
MyBase.New()
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Slices = New PieSlice() {New PieSlice, New PieSlice, _
New PieSlice, New PieSlice}
Me.OnResize(EventArgs.Empty)
End Sub
Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
MyBase.OnResize(e)
Dim r As Rectangle = Me.ClientRectangle
r.Width -= 1
r.Height -= 1
For id As Int32 = 0 To 3
Slices(id).Path.Reset()
Slices(id).Path.AddPie(r, 45 + (id * 90), 90)
Next
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
If Slices.Length = 0 Then Return
For Each slice As PieSlice In Slices
If slice.Checked Then
e.Graphics.FillPath(Brushes.Red, slice.Path)
Else
e.Graphics.FillPath(Brushes.Blue, slice.Path)
End If
e.Graphics.DrawPath(Pens.Gray, slice.Path)
Next
End Sub
Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
MyBase.OnClick(e)
For Each slice As PieSlice In Slices
Dim pt As Point = Me.PointToClient(Me.MousePosition)
If slice.Path.IsVisible(pt.X, pt.Y) Then
slice.Checked = Not slice.Checked
Me.Invalidate(New Region(slice.Path))
End If
Next
End Sub
End Class
///
It just means that you added a UserControl to the project which also adds a
Partial class and auto-generated code, whereas I added a Class so didn't get
any extras.
In Sub New() just replace
MyBase.New()
with
InitializeComponent()
I also put
Me.PointToClient(Me.MousePosition)
in OnClick() but it should have been
Me.PointToClient(Control.MousePosition)
--
Mick Doherty http://dotnetrix.co.uk/nothing.html
<Je**@aol.comwrote in message
news:ta********************************@4ax.com...
Try the code and got the following warning
Public Sub New()' in designer-generated type 'Project1.CheckPie'
should call InitializeComponent method.
Not sure what this means This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Nevets Steprock |
last post by:
I'm writing a web program where one of the sections is supposed to output a
correlation matrix. The typical correlation matrix looks like this:
..23
..34 .54
..76 .44 .28
..02 .77 ...
|
by: KinGPIN |
last post by:
hi ; I have a homework about CMatrix; and i had a problem ;in my
homowork i hace functions and operators written for CMatrix class(this
was my first homework); it is wanted to inherite the...
|
by: empire5 |
last post by:
I want to eliminate the little triangular arrow poinger that appears tot he
right of the menu item. Which control setting lets me do that.
|
by: mo/-/sin |
last post by:
hi........... i m mohsin
plz provide me the program which represents triangular matrix in c
language.........
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
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...
|
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,...
|
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...
|
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...
| |