|
-
Jun 4th, 2008, 09:25 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] Is there a group box for CF 3.5
Hello,
I want to use a group box. However, I haven't found one in the tool box for VS 2008 CF 3.5.
I tried to create a class library and thought I could make one by inheriting from the GroupBox class. However, I wasn't able to do this, as there is only the namspace (GroupBox) for the system.windows.forms. And not the GroupBox class.
Is it possible to create a new group box control?
Any ideas to push me into the right direction?
Steve
-
Jun 5th, 2008, 01:55 AM
#2
Frenzied Member
Re: Is there a group box for CF 3.5
Hi,
there is a group box in OpenNetCf - the best you get from .Net is a panel
-
Jun 5th, 2008, 10:44 PM
#3
Re: Is there a group box for CF 3.5
Hello there,
Hopefully this will be of use to you.
Code:
''' <summary>
''' Implementation of a User Control that will display a group box around a number of controls.
''' <remarks>The GroupBox does not act as a container for the controls that are displayed inside it.</remarks>
''' </summary>
Public Class GroupBox
''' <summary>
''' Paint Handler for the GroupBox control.
''' During paint messages we display a border around the client area, which really is the
''' implementation of the GroupBox. The label that is hosted on the GroupBox control is
''' painted last, so it overwrites part of the border, which is exactly the desired behavior.
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
Private Sub GroupBox_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim g As Graphics = e.Graphics
Dim x1 As Integer = 0 ' location of the left side of the group box
Dim x2 As Integer = ClientRectangle.Width ' location of the right side of the group box
Dim y1 As Integer = Label1.Location.Y + (Label1.Size.Height / 2) ' top of the group box
Dim y2 As Integer = ClientRectangle.Height ' bottom of the group box
If (g.DpiX = 96) Then
Dim drawingPen As Pen = New Pen(Color.Black, 1)
g.DrawLine(drawingPen, x1, y1, x2, y1) ' Draw the top line of the group box
g.DrawLine(drawingPen, x1, y1, x1, y2) ' Draw the left line of the group box
g.DrawLine(drawingPen, x1, y2 - 1, x2, y2 - 1) ' Draw the bottom line of the group box
g.DrawLine(drawingPen, x2 - 1, y1, x2 - 1, y2) ' Draw the right line of the group box
drawingPen.Dispose()
Else
' PocketPC with 192 DPI resolution, meaning we need to double pixels to draw similar results
Dim drawingPen As Pen = New Pen(Color.Black, 2)
g.DrawLine(drawingPen, x1, y1, x2, y1) ' Draw the top line of the group box
g.DrawLine(drawingPen, x1 + 1, y1, x1 + 1, y2) ' Draw the left line of the group box
g.DrawLine(drawingPen, x1, y2 - 1, x2, y2 - 1) ' Draw the bottom line of the group box
g.DrawLine(drawingPen, x2 - 1, y1, x2 - 1, y2) ' Draw the right line of the group box
drawingPen.Dispose()
End If
End Sub
''' <summary>
''' Constructor of the GroupBox user control.
''' </summary>
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
End Sub
''' <summary>
''' TextChanged event handler for the label that is displayed on the GroupBox.
''' In the TextChanged event handler we simply resize the label to make it look good
''' inside the GroupBox control.
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks>Currently we are using _penWidth to distinquish between VGA and normal PPC screens</remarks>
Private Sub Label1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.TextChanged
Dim gfx As Graphics = Me.CreateGraphics()
Dim size As SizeF = gfx.MeasureString(Label1.Text, Label1.Font)
If (gfx.DpiX = 96) Then
Label1.Width = size.Width + 4
Label1.Height = size.Height
Else
' PocketPC with 192 DPI resolution
' Since Measure string returns a number of pixels, but the label width scales down to 96 DPI
' we have to take half the size to set the correct width of the label.
Label1.Width = size.Width / 2 + 4
Label1.Height = size.Height / 2 + 1
End If
gfx.Dispose()
End Sub
''' <summary>
''' Sets or Gets the Text value of the label control that is part of the GroupBox.
''' Note that using a property, the Title will automatically appear in the Properties
''' pane on the designer when you add the user control to a form. You can set the
''' value of the property during design time.
''' </summary>
''' <value>string - New Text value for the label</value>
''' <returns>string - Current Text value of the label</returns>
''' <remarks></remarks>
Public Property Title() As String
Get
Return Label1.Text
End Get
Set(ByVal value As String)
Label1.Text = value
End Set
End Property
End Class
This was taken from an example application that I found here
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|