this code lets me set the location of the form each time I drag my map.
Private Sub map_OnMapDrag() Handles map.OnMapDrag
If f2c1.Visible Then
f2c1.Location = camera1.LocalPosition + New Point(20, -240)
End If
If f2c2.Visible Then
f2c2.Location = camera2.LocalPosition + New Point(20, -240)
End If
If f2c3.Visible Then
f2c3.Location = camera3.LocalPosition + New Point(20, -240)
End If
End Sub
however, I want it on a public sub..
and this code, which I think gets all the visible forms ..
Dim forms = Application.OpenForms.OfType(Of frmCamera)()
While forms.Count > 0
forms(forms.Count - 1).Visible = True
End While
how can I make it so that all visible forms gets their location everytime I drag it, so that even if I dynamically added another form it won't be a problem. that's my goal.
can you guys fix this for me..
Dim forms = Application.OpenForms.OfType(Of frmCamera)()
While forms.Count > 0
forms(forms.Count - 1).Visible = True
End While
forms.Location = 'location that I want
Try this:
Dim forms As Collections.Generic.IEnumerable(Of frmMain) = Application.OpenForms.OfType(Of frmMain).Where(Function(frm) frm.Visible)
For Each f As Form In forms
f.Location = New Point(0, 0) ' set coordinate as needed
Next
Related
I have a form with a tabcontrol, the tabscontrol starts with a single tab and more are added dynamically if need be. Each tab holds around 20 seperate panels which are used to represent pages. It can handle 12 tabs fine and continue adding more way past 40. However, whenever you click on a tab to load it up it throws this error.
System.ComponentModel.Win32Exception.
With no location in the code to wear it crashed.
I've tried this on multiple machines and the same thing happens.
This is the code to adding a new tab.
Public Sub CreateAnotherPage5(NoOfPage5 As Integer)
For i = 1 To NoOfPage5
Dim PG5E As New ConditionReportPage5
Dim PREV As ConditionReportPage5
If NoOfPages Mod 20 = 0 Then
Dim NwTabPG As New TabPage
Dim NwPanel As New PanelAutoScroll
NoOfTabs = NoOfTabs + 1
NwTabPG.Name = "tpg_" & NoOfTabs
NwPanel.Name = "pnl_" & NoOfTabs
NwTabPG.Text = NoOfTabs
NwPanel.Dock = DockStyle.Fill
NwPanel.AutoScroll = True
frm_Main.tbc_Main.TabPages.Add(NwTabPG)
NwTabPG.Controls.Add(NwPanel)
PG5E.Location = New Point(frm_Main.FirstPageX, frm_Main.FirstPageY)
NwPanel.Controls.Add(PG5E)
NoOfPages = 1
Else
Dim PrevPanl As PanelAutoScroll
Dim PrevTabPG As TabPage
PrevTabPG = frm_Main.tbc_Main.Controls.Item("tpg_" & NoOfTabs)
PrevPanl = PrevTabPG.Controls.Item("pnl_" & NoOfTabs)
PREV = TryCast(PrevPanl.Controls(NoOfPages - 1), ConditionReportPage5)
PG5E.Location = New Point(frm_Main.FirstPageX, Math.Abs(PREV.Location.Y + 1000))
PrevPanl.Controls.Add(PG5E)
NoOfPages = NoOfPages + 1
End If
ExtensionConfig.DoubleBuffer(PG5E, True)
PG5E.SetNewDef()
PG5E.PageNo = NoOfPages
End sub
Any suggestions?
I am trying to use windows forms vb.net. Created a simple form with datepicker controls.
These controls are dynamically created. I am using infragistics datepicker here
dtpicker = New UltraDateTimeEditor
dtpicker.Name = "Date" + i.ToString()
dtpicker.MaskInput = "{date} hh:mm"
dtpicker.MaskDisplayMode = MaskMode.IncludeBoth
dtpicker.SpinButtonDisplayStyle = Infragistics.Win.ButtonDisplayStyle.Always
dtpicker.Height = 20
dtpicker.Width = 140
'horizontal
dtpicker.Location = New Point((i * 140), 100)
AddHandler dtpicker.Leave, AddressOf dtpicker_Leave
I have added leave event. But the problem is leave event is fired twice. Please suggest me how to fix or use other correct event.
My data saving logic on leave event looks like this
If Not DBNull.Value.Equals(chkdtFlowPanel.Rows.Item(0).Item("ConveyanceID")) AndAlso Not DBNull.Value.Equals(chkdtFlowPanel.Rows.Item(0).Item("TripID")) Then
ScreenProperty.ARG_ConveyanceID = chkdtFlowPanel.Rows.Item(0).Item("ConveyanceID")
ScreenProperty.ARG_TripID = chkdtFlowPanel.Rows.Item(0).Item("TripID")
Dim prevDatevalue As Object = Nothing
For Each o As Object In UltraPanel1.ClientArea.Controls
If TypeOf (o) Is UltraDateTimeEditor Then
Dim datePicker As UltraDateTimeEditor = o
If prevDatevalue <> Nothing AndAlso datePicker.Value <> Nothing Then
If datePicker.Value < prevDatevalue Then
' Do something Previous value is Lesser
'lblSuccess.Text = "Please verify date entered."
'lblSuccess.ForeColor = Color.Red
Exit Sub
End If
End If
ScreenProperty.ARG_CheckPointTimeID = Convert.ToInt32(datePicker.Tag.Split(","c)(0))
ScreenProperty.ARG_TerminalCheckPointID = Convert.ToInt32(datePicker.Tag.Split(","c)(1))
ScreenProperty.ARG_CheckPointTimeValue = datePicker.Value
Helper.InsertCheckPointTimes(CType(ScreenProperty, KMCommonUITemplates.CUTScreenProperty), Me)
prevDatevalue = datePicker.Value
'lblSuccess.Text = "Data Saved Successfully."
'lblSuccess.ForeColor = Color.Green
End If
Next
'Else
' lblSuccess.Text = "Selected Order does not have Trip/Conveyance created."
' lblSuccess.ForeColor = Color.Red
End If
'Helper.GetCheckPointFlowByTerminalID(CType(ScreenProperty, KMCommonUITemplates.CUTScreenProperty), Me)
ClearText()
I'm new to vb.net and always searching for solution. My forms involved are MainMenu, poCustom, and rdlcForm. All are working well until I got a new look with MDI Forms.
My "New" MainMenu are now containing the poCustom into a Groupbox. Which I searched the code as
For Each f As Form In Application.OpenForms
If TypeOf f Is poCustom Then
f.Activate()
Return
End If
Next
Dim ch As New poCustom
ch.TopLevel = False
ch.Visible = True
ch.StartPosition = FormStartPosition.Manual
Dim leftStart As Integer = 1220 - (ch.Width + (SystemInformation.Border3DSize.Width * 2))
Dim topStart As Integer = 670 - (ch.Height + (SystemInformation.Border3DSize.Height * 2))
ch.Location = New Point(leftStart, topStart)
GroupBox1.Controls.Add(ch)
Problem: The rdlcForm(report) cannot get the value of textboxes in poCustom form. Code below:
Private Sub rptPOView2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim rptParam1(11) As Microsoft.Reporting.WinForms.ReportParameter
rptParam1(0) = New Microsoft.Reporting.WinForms.ReportParameter("rptDate", poCustom.Label1.Text)
rptParam1(1) = New Microsoft.Reporting.WinForms.ReportParameter("rptREF", poCustom.Label5.Text)
rptParam1(2) = New Microsoft.Reporting.WinForms.ReportParameter("rptCompany", poCustom.CompanyName.Text)
rptParam1(3) = New Microsoft.Reporting.WinForms.ReportParameter("rptQTY", poCustom.txBoxQTY.Text)
rptParam1(4) = New Microsoft.Reporting.WinForms.ReportParameter("rptUOM", poCustom.txBoxUOM.Text)
rptParam1(5) = New Microsoft.Reporting.WinForms.ReportParameter("rptDesciption", poCustom.txBoxDesc.Text)
rptParam1(6) = New Microsoft.Reporting.WinForms.ReportParameter("rptUnit", poCustom.txBoxUnit.Text)
rptParam1(7) = New Microsoft.Reporting.WinForms.ReportParameter("rptTotal", poCustom.txBoxTotal.Text)
rptParam1(8) = New Microsoft.Reporting.WinForms.ReportParameter("rptSubTotal", poCustom.Label25.Text)
rptParam1(9) = New Microsoft.Reporting.WinForms.ReportParameter("rptVAT", poCustom.Label26.Text)
rptParam1(10) = New Microsoft.Reporting.WinForms.ReportParameter("rptTotalAmount", poCustom.Label27.Text)
rptParam1(11) = New Microsoft.Reporting.WinForms.ReportParameter("rptRequest", poCustom.Label30.Text)
ReportViewer1.LocalReport.SetParameters(rptParam1)
Me.ReportViewer1.RefreshReport()
TextBox1.Text = poCustom.CompanyName.Text
End Sub
Which happens to work without using MDI Forms. I would like to know the cause of the problem for future use. Thank you in advance!
You are using two different instances of poCustom. ch is the first, and you populate its textboxes. But on the rptPOView2_Load event, you are using the other instance, which contains textboxes that has no value yet. One way to fix the problem is to use poCustom itself and not ch.
poCustom.TopLevel = False
poCustom.Visible = True
poCustom.StartPosition = FormStartPosition.Manual
Dim leftStart As Integer = 1220 - (ch.Width + (SystemInformation.Border3DSize.Width * 2))
Dim topStart As Integer = 670 - (ch.Height + (SystemInformation.Border3DSize.Height * 2))
poCustom.Location = New Point(leftStart, topStart)
GroupBox1.Controls.Add(poCustom)
I'm very new to programming and vb.net, trying to self teach more so as a hobby, as I have an idea for a program that I would find useful, but I am having trouble getting past this issue and I believe it is to do with the timer.
I have a form of size.(600,600) with one button of size.(450,150) that is set location(100,50) on the form. When clicked I want to move down it's own height, then add a new button in it's place. The code included below works as desired for the first two clicks, but on the third click the button keeps moving and the autoscroll bar extends. I initially thought it was the autoscroll function or the location property, but realised that as the button keeps moving, the timer hasn't stopped. I am aware that the code is probably very clunky in terms of achieving the outcome, and that there are a few lines/variables that are currently skipped over by the compiler (these are from older attempts to figure this out).
I have looked around and can't find the cause of my problem. Any help would be greatly appreciated. Apologies if the code block looks messy - first go.
Public Class frmOpenScreen
Dim intWButtons, intCreateButtonY, intCreateButtonX 'intTimerTick As Integer
Dim arrWNames() As String
Dim ctrlWButtons As Control
Dim blnAddingW As Boolean
Private Sub btnCreateW_Click(sender As System.Object, e As System.EventArgs) Handles btnCreateW.Click
'Creates new Button details including handler
Dim strWName, strWShort As String
Dim intCreateButtonY2 As Integer
Static intNumW As Integer
Dim B As New Button
strWName = InputBox("Please enter the name name of the button you are creating. Please ensure the spelling is correct.", "Create W")
If strWName = "" Then
MsgBox("Nothing Entered.")
Exit Sub
End If
strWShort = strWName.Replace(" ", "")
B.Text = strWName
B.Width = 400
B.Height = 150
B.Font = New System.Drawing.Font("Arial Narrow", 21.75)
B.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink
B.Anchor = AnchorStyles.Top
B.Margin = New Windows.Forms.Padding(0, 0, 0, 0)
'Updates Crucial Data (w name array, number of w buttons inc Create New)
If intNumW = 0 Then
ReDim arrWNames(0)
Else
intNumW = UBound(arrWNames) + 1
ReDim Preserve arrWNames(intNumW)
End If
arrWNames(intNumW) = strWShort
intNumW = intNumW + 1
intWButtons = WButtonCount(intWButtons) + 1
'updates form with new button and rearranges existing buttons
intCreateButtonY = btnCreateW.Location.Y
intCreateButtonX = btnCreateW.Location.X
‘intTimerTick = 0
tmrButtonMove.Enabled = True
‘Do While intTimerTick < 16
‘ 'blank to do nothing
‘Loop
'btnCreateW.Location = New Point(intCreateButtonX, intCreateButtonY + 150)
B.Location = New Point(intCreateButtonX, intCreateButtonY)
Me.Controls.Add(B)
B.Name = "btn" & strWShort
intCreateButtonY2 = btnCreateW.Location.Y
If intCreateButtonY2 > Me.Location.Y Then
Me.AutoScroll = False
Me.AutoScroll = True
Else
Me.AutoScroll = False
End If
'MsgBox(intCreateButtonY)
End Sub
Function WButtonCount(ByRef buttoncount As Integer) As Integer
buttoncount = intWButtons
If buttoncount = 0 Then
Return 1
End If
Return buttoncount
End Function
Public Sub tmrButtonMove_Tick(sender As System.Object, e As System.EventArgs) Handles tmrButtonMove.Tick
Dim intTimerTick As Integer
If intTimerTick > 14 Then
intTimerTick = 0
End If
If btnCreateW.Location.Y <= intCreateButtonY + 150 Then
btnCreateW.Top = btnCreateW.Top + 10
End If
intTimerTick += 1
If intTimerTick = 15 Then
tmrButtonMove.Enabled = False
End If
End Sub
End Class
So my current understanding is that the tick event handler should be increasing the timertick variable every time it fires, and that once it has hits 15 it should diable the timer and stop the button moving, but it is not doing so.
Thanks in advance.
IntTimerTick is initialized to 0 at the beginning of every Tick event. This won't happen if you declare it to be static:
Static Dim intTimerTick As Integer
This is a VB.NET, Winforms App. I have a datagridview on "Form1" that uses a databinding.datasource which is an Entity Framework table. I fill the datagridview with the below function on Form1:
Sub PM_UnitViewGrid()
Try
_form1.UnitsBindingSource.DataSource = db.units.Where(Function(f) f.propertyId = _form1.CurrentPropertyId).OrderBy(Function(F) F.unitNumber)
_form1.UnitDataGridView.DataSource = _form1.UnitsBindingSource.DataSource
Dim iCount As Integer = _form1.UnitDataGridView.RowCount
For x As Integer = 0 To iCount - 1
If Not IsNothing(_form1.UnitDataGridView.Rows(x).Cells(4).Value) Then
Dim tid As Integer = _form1.UnitDataGridView.Rows(x).Cells(4).Value
Dim _ten As tenant = db.tenants.Single(Function(f) f.Occupantid = tid)
_form1.UnitDataGridView.Rows(x).Cells(1).Value = _ten.first_name + ", " + _ten.last_name
Else
Dim btnColumn As DataGridViewButtonCell = CType(_form1.UnitDataGridView.Rows(x).Cells(1), DataGridViewButtonCell)
btnColumn.Style.BackColor = Color.Green
_form1.UnitDataGridView.Rows(x).Cells(1).Value = "VACANT"
End If
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Return
End Sub
This works great and also assigns the needed values to an unbound column. The problem is that the cells(1) is a button. Which when clicked takes the user to another form as a new dialog window. The function for which is below. However, once the changes are made in that form I need for the datagridview to refresh the data that its using from the database and show the correct data. As it stands right now the values are not updating on the datagridview unless the app is completely exited and restarted. Nothing I have found seems to work and Refresh and Update only redraw the control. I need the underlying datasource to refresh and then the datagridview once the child form is exited.. This has had me stumped for a good 36 hours now and I am lost as to why nothing I am trying is working. ANY and all help would be greatly appreciated.
The sub that loads the child form based on the cells(1) button clicked is as follows:
Private Sub UnitDataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles UnitDataGridView.CellContentClick
UnitDataGridView.CommitEdit(DataGridViewDataErrorContexts.CurrentCellChange)
Dim y As DataGridViewCellEventArgs = e
Dim Tid As Integer = Nothing
If e.ColumnIndex = 1 Then
If Not e.RowIndex = -1 Then
If Not IsNothing(UnitDataGridView.Rows(e.RowIndex).Cells(4).Value) Then
currentTenent = UnitDataGridView.Rows(e.RowIndex).Cells(4).Value
TenentIdentification = currentTenent
If Not IsNothing(e) Then
If Not IsNothing(UnitDataGridView.Rows(e.RowIndex).Cells(4).Value) Then
Tid = UnitDataGridView.Rows(e.RowIndex).Cells(4).Value
Dim _ten As tenant = db.tenants.Single(Function(f) f.Occupantid = Tid) 'tenant is a table entity
TenantViewSubs.tenId = _ten.Occupantid
Dim t As New TenantView
t.tenId = tid
t.ShowDialog()
End If
End If
PropertyManagSubs.PM_UnitViewGrid() 'This is the function that is above that fills the datagridview
Else
Dim uTview As New UnassignedTenants
uTview.selectedProperty = selectedProperty 'selectedProperty is Integer
uTview.ShowDialog()
PropertyManagSubs.PM_UnitViewGrid() 'This is the function that is above that fills the datagridview
End If
End If
End If
End Sub
I tried each of the following code blocks after the t.ShowDialog() line with no change at all.
UnitDataGridView.Refresh()
.
UnitsBindingSource.Dispose()
UnitsBindingSource.DataSource = db.units.Where(Function(f) f.propertyId = selectedProperty).OrderBy(Function(f) f.unitNumber)
UnitDataGridView.DataSource = UnitsBindingSource.DataSource
.
UnitsBindingSource.DataSource = nothing
unitsBindingSource.DataSource = db.units.Where(Function(f) f.propertyId = selectedProperty).OrderBy(Function(f) f.unitNumber)
UnitDataGridView.DataSource = UnitsBindingSource.DataSource
I finally fixed this on my own.. It was in the way I passed my db context to the databinding..
I simply wrote the below sub:
Private Sub UpdateValues()
Dim context As New storageEntities 'storageEntities is an Entity
Dim query = context.units.Where(Function(F) F.propertyId = selectedProperty).OrderBy(Function(f) f.unitNumber)
UnitDataGridView.DataSource = query
End Sub
Then anytime a child form updated data I simply call
UpdateValues()
After the dialog box closes.
This may help someone else with the same problems so that is why I am posting it.