Forms Control Suggestion for availability module
-
Thursday, April 12, 2012 8:47 AM
Dear all,
Please refer to the picture below.
I'm building a apps that which allow to check the room availability for a hostel.
I am looking some controls which is similiar to the following which allowed me to change the color of the box during runtime.
Is there any suggestion.
Thanks all
All Replies
-
Thursday, April 12, 2012 10:58 AM
This is quickly done with your own Usercontrol. Dock two labels and a Tablelayoutpanel (2 rows, 6 columns) containing 12 labels. Add the properties date and "RoomOccupied(Number as integer) as boolean". EDIT: Setting the latter changes the colors of the corresponding label.
Armin
- Edited by Armin Zingler Thursday, April 12, 2012 11:25 AM property "Roomname" doesn't make sense
- Proposed As Answer by Cor LigthertMVP Thursday, April 12, 2012 2:58 PM
-
Thursday, April 12, 2012 11:18 AM
You see, this was written in 15 minutes:
EDIT: I actually don't know what "ROOM" means (I know what a room is, but....) ;)
Armin
- Edited by Armin Zingler Thursday, April 12, 2012 11:31 AM
-
Thursday, April 12, 2012 11:49 AM
You see, this was written in 15 minutes:
EDIT: I actually don't know what "ROOM" means (I know what a room is, but....) ;)
Armin
hi armin..
great one.. would u mind to share with me the piece of code?
my email address is limcheehang@hotmail.com.
Thank you
-
Thursday, April 12, 2012 11:57 AM
Roomlabel.vb
Friend Class RoomLabel Inherits Label Private Class ColorCombination Public ForeColor, BackColor As Color End Class Private Shared ReadOnly _FreeColors As New ColorCombination With {.backColor = Color.Green, .ForeColor = Color.White} Private Shared ReadOnly _OccupiedColors As New ColorCombination With {.backColor = Color.White, .ForeColor = Color.Black} Private _Occupied As Boolean Public Sub New() BorderStyle = Windows.Forms.BorderStyle.FixedSingle TextAlign = ContentAlignment.MiddleCenter Margin = New Padding(2) AutoSize = False Dock = DockStyle.Fill UpdateColors() End Sub Public Property Occupied() As Boolean Get Return _Occupied End Get Set(ByVal value As Boolean) If _Occupied = value Then Return _Occupied = value UpdateColors() End Set End Property Private Sub UpdateColors() Dim colors = If(_Occupied, _OccupiedColors, _FreeColors) BackColor = colors.BackColor ForeColor = colors.ForeColor End Sub End Class
RoomOccupationForOneDayControl.vb:
Public Class RoomOccupationForOneDayControl Private ReadOnly _RoomLabels() As RoomLabel Private _Day As Date = DateTime.Today Sub New() Dim RoomCount As Integer InitializeComponent() RoomCount = ctlDays.ColumnCount * ctlDays.RowCount Dim q = From i In Enumerable.Range(1, RoomCount) _ Select New RoomLabel With {.Text = i.ToString} _RoomLabels = q.ToArray ctlDays.Controls.AddRange(_RoomLabels) UpdateDayLabel() UpdateDayFont() End Sub Protected Overrides Sub OnFontChanged(ByVal e As System.EventArgs) MyBase.OnFontChanged(e) UpdateDayFont() End Sub Private Sub UpdateDayFont() ctlDay.Font = New Font(Font, FontStyle.Bold) End Sub Public Property RoomOccupied(ByVal RoomNumber As Integer) As Boolean Get Return _RoomLabels(RoomNumber - 1).Occupied End Get Set(ByVal value As Boolean) _RoomLabels(RoomNumber - 1).Occupied = value End Set End Property Public Property Day() As Date Get Return _Day End Get Set(ByVal value As Date) _Day = value UpdateDayLabel() End Set End Property Private Sub UpdateDayLabel() ctlDay.Text = _Day.ToString("MM-dd") End Sub End Class
RoomOccupationForOneDayControl.Designer.vb
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ Partial Class RoomOccupationForOneDayControl Inherits System.Windows.Forms.UserControl 'UserControl überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) Try If disposing AndAlso components IsNot Nothing Then components.Dispose() End If Finally MyBase.Dispose(disposing) End Try End Sub 'Wird vom Windows Form-Designer benötigt. Private components As System.ComponentModel.IContainer 'Hinweis: Die folgende Prozedur ist für den Windows Form-Designer erforderlich. 'Das Bearbeiten ist mit dem Windows Form-Designer möglich. 'Das Bearbeiten mit dem Code-Editor ist nicht möglich. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.ctlDay = New System.Windows.Forms.Label Me.ctlRoom = New System.Windows.Forms.Label Me.ctlDays = New System.Windows.Forms.TableLayoutPanel Me.SuspendLayout() ' 'ctlDay ' Me.ctlDay.BackColor = System.Drawing.Color.White Me.ctlDay.Dock = System.Windows.Forms.DockStyle.Top Me.ctlDay.Location = New System.Drawing.Point(3, 3) Me.ctlDay.Name = "ctlDay" Me.ctlDay.Size = New System.Drawing.Size(367, 21) Me.ctlDay.TabIndex = 0 Me.ctlDay.Text = "Label1" Me.ctlDay.TextAlign = System.Drawing.ContentAlignment.MiddleLeft ' 'ctlRoom ' Me.ctlRoom.BackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(192, Byte), Integer), CType(CType(255, Byte), Integer)) Me.ctlRoom.Dock = System.Windows.Forms.DockStyle.Top Me.ctlRoom.Location = New System.Drawing.Point(3, 24) Me.ctlRoom.Name = "ctlRoom" Me.ctlRoom.Size = New System.Drawing.Size(367, 23) Me.ctlRoom.TabIndex = 1 Me.ctlRoom.Text = "ROOM" Me.ctlRoom.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ' 'ctlDays ' Me.ctlDays.ColumnCount = 6 Me.ctlDays.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16.66667!)) Me.ctlDays.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16.66667!)) Me.ctlDays.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16.66667!)) Me.ctlDays.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16.66667!)) Me.ctlDays.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16.66667!)) Me.ctlDays.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16.66667!)) Me.ctlDays.Dock = System.Windows.Forms.DockStyle.Fill Me.ctlDays.Location = New System.Drawing.Point(3, 47) Me.ctlDays.Name = "ctlDays" Me.ctlDays.RowCount = 2 Me.ctlDays.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50.0!)) Me.ctlDays.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50.0!)) Me.ctlDays.Size = New System.Drawing.Size(367, 82) Me.ctlDays.TabIndex = 2 ' 'RoomOccupationForOneDayControl ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.Controls.Add(Me.ctlDays) Me.Controls.Add(Me.ctlRoom) Me.Controls.Add(Me.ctlDay) Me.Name = "RoomOccupationForOneDayControl" Me.Padding = New System.Windows.Forms.Padding(3) Me.Size = New System.Drawing.Size(373, 132) Me.ResumeLayout(False) End Sub Friend WithEvents ctlDay As System.Windows.Forms.Label Friend WithEvents ctlRoom As System.Windows.Forms.Label Friend WithEvents ctlDays As System.Windows.Forms.TableLayoutPanel End Class
On the test form (Form1) add a TableLayoutpanel named ctlTLP with 8 columns and 4 rows. Then use this code:
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load For i = 1 To 32 Dim ctl = New RoomOccupationForOneDayControl ctl.Day = Date.Today.AddDays(i - 1) ctlTLP.Controls.Add(ctl) ctl.Dock = DockStyle.Fill Next End Sub End Class
Armin
- Edited by Armin Zingler Thursday, April 12, 2012 11:57 AM
- Marked As Answer by Shanks ZenMicrosoft Contingent Staff, Moderator Wednesday, April 25, 2012 9:19 AM
-
Thursday, April 12, 2012 12:03 PMMaybe you have to change the font size. Got lost somehow.
Armin
-
Thursday, April 12, 2012 2:34 PM
@

@Lim and Armin
Sorry I could not resist when I saw Armin asking this
EDIT: I actually don't know what "ROOM" means (I know what a room is, but....) ;)
The most used display in Germany.
Beside this one of course
Cor
- Edited by Cor LigthertMVP Thursday, April 12, 2012 2:48 PM
-
Friday, April 13, 2012 6:32 AM
Hi Armin,
I have tried to use ur code to generate the samething. But i failed to get such result. Don't mind can help me to take a look of the code??
Thank you
-
Friday, April 13, 2012 10:15 AM
I have tried to use ur code to generate the samething. But i failed to get such result. Don't mind can help me to take a look of the code??
I'm sorry, flash player is required, and I enable it only for known sites.
Maybe I should have added:
Roomlabel.vb is a simple class file.
RoomOccupationForOneDayControl is a UserControl (Project -> Add Usercontrol). Probably you know it is made of two source code files. One is RoomOccupationForOneDayControl.vb, the other one is RoomOccupationForOneDayControl.Designer.vb and it is hidden. To show the hidden files press this button
at the top of the solution explorer.
Armin
- Edited by Armin Zingler Friday, April 13, 2012 10:15 AM
-
Friday, April 13, 2012 2:21 PM
hi armin.
Maybe u yousendit link better than u.
https://www.yousendit.com/download/M3BrN3RVMVh0d0d4djlVag
actually i have created the files as mentioned an no error found. Just the outcome is different from what u shown.
-
Friday, April 13, 2012 3:22 PM
actually i have created the files as mentioned an no error found. Just the outcome is different from what u shown.
In what way isn't the result not satisfying? Note that I've made some changes after posting the screenshots, but it mainly affects the colors.
(With my current situation I can't have a look at your code. I'm using VS 2008 so I can't open it. I can use VB 2010 Express in a VM using VirtualBox, but I can't start it as as I'm currently working with VirtualPC and both can not run in parallel if CPU virtualization is enabled.)
Armin

