from a question here : Question
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
UPDATE the above code gets all visible forms but since its generic, all the visible forms appear on one place..
let's say, I have 3 markers.. named camera1 camera2 camera3..
on Form_Load I will click those 3 markers, and a supposed video feed will appear (in this case, each with a new instance of form2)
this is my code in which does what I want, only problem is, I want it to be reusable for the future of dynamically adding more rather than this, predefined.
Dim f2c1 As New Form2
Dim f2c2 As New Form2
Dim f2c3 As New Form2
If f2c1.Visible = True Then
f2c1.Location = camera1.LocalPosition + New Point(20, -240)
End If
If f2c2.Visible = True Then
f2c2.Location = camera2.LocalPosition + New Point(20, -240)
End If
If f2c3.Visible = True Then
f2c3.Location = camera3.LocalPosition + New Point(20, -240)
End If
that code, is this.. If I click the marker, drag the map. video feed form2 stays with them.
I want it on a function or sub that will do this..
'Public Sub when I drag the map()
'every form visible
'will follow -- let's say, will follow what marker clicked them
ask me if you need anything.. thanks
I did some workaround
Dim mList As New List(Of String)
marker.ToolTipMode = MarkerTooltipMode.Always 'as an indetifier of each markers as
marker.ToolTipText = dtrow("MarkerName") 'I have added it to a for each
Try
For Each m In mList 'get items from the list
If item.ToolTipText = m Then 'check same name
Dim f As New Form2
With f
If .Visible = True Then
.Hide()
Else
.Show()
Dim p As New Point
p = item.LocalPosition + New Point(20, -240)
.Location = p 'after I click form will appear right next to them
.Text = m
End If
End With
Exit Sub
End If
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
this is still not the ideal thing that is on my mind, but this practically answers my question for the moment.
Related
I posted a question here and, after many attempts, I accepted the answer who suggested me to use an hidden control instead of an added control.
This way my code run correctly but I would like to understand the mistake.
That's what happens:
When I press a button a new DataGridView is added but
a) it isn't visible even if his property visible is set True;
b) if (while the added DGV is on the form) I set DGV property visible to False and then I re-set it to True the DGV appears but columns aren't resized;
c) if I remove the added DGV and re-add it, it is "invisible" again.
ALL THESE TROUBLES DON'T HAPPEN IF I RUN ANOTHER SUB
If:
a) I run a sub that hides my first form and shows another form;
b) then I close the 2nd form to go back to the first form;
all works fine:
the DGV is correctly added;
it is visible;
all columns are correctly resized;
if I remove the DGV or re-add it, all still works.
Where am I wrong?
This is the code I got from your earlier link. It shows the datagridview as expected in my form. As you can see, it is exactly your code, with the exception of that "using" block --- and the way you retrieve the datatable. That's the only two differences.
Private Sub ShowHideTbl()
Dim DTemp As DataTable = GetTable()
Dim DGV_Tbl As DataGridView = Nothing
Try
DGV_Tbl = CType(Me.Controls("DGV_Tbl"), DataGridView)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
If DGV_Tbl Is Nothing Then
If Me.CBox_ProcType.Text = "Select a Procedure" Then
MsgBox("You need To select a Procedure", vbInformation, "Unable to show table")
Exit Sub
End If
End If
DGV_Tbl = New DataGridView
With DGV_Tbl
.Name = "DGV_Tbl"
.DataSource = DTemp
Me.Controls.Add(DGV_Tbl)
.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells)
.RowHeadersVisible = False
.AllowUserToAddRows = False
.AllowUserToDeleteRows = False
End With
Dim DGV_H As Integer = 0
Dim DGV_W As Integer = 0
For Each S As DataGridViewRow In DGV_Tbl.Rows
DGV_H += S.Height
Next
DGV_H += DGV_Tbl.ColumnHeadersHeight
'Add more space to include spaces between cells
DGV_H += CInt(DGV_Tbl.Rows.Count * 0.45)
For Each S As DataGridViewColumn In DGV_Tbl.Columns
DGV_W += S.Width
Next
'Add more space to include spaces between cells
DGV_W += CInt(DGV_Tbl.Columns.Count * 0.45)
DGV_Tbl.Height = DGV_H
DGV_Tbl.Width = DGV_W
'Resize the Form
Me.Height += DGV_H + 30
Me.Controls("DGV_Tbl").Location = New Point(15, Me.Height - DGV_H - 30)
End Sub
Your problem is most strange, and since I don't have the code to try and test, my only suggest is that you paste this code into a new form, see if it works. If it does, then add your other control of form 1 into it, run the code again, see if it still work. Repeat the process until you find out what is the cause.
I believe you can find out what is really happening in your form with this. Who know, that new form will probably work.
(initial guess at nested proved to be incorrect. Problem seems to be that SplitContainer panels do not scale their hosted controls properly.)
I have some forms that have tab controls that fail to resize properly at load time. https://support.microsoft.com/en-us/kb/953934 describes such a kernel bug in 2008. Hard to believe it hasn't been fixed. I think it went away for a while but I'm beginning to see problems again.
The controls are nested pretty deep. Midi Parent, child form, tab control, splitter control with two panels and controls. For the top down the first control with the problem is the tab control. It resizes when the form is resized after loading but the anchors are incorrect and part of the control is clipped.
The problem seems to be specific to 100% desktop font size - desktops with 100+ size work OK. I develop at 125% using VS 2013 v5 - the issue was present on v4 as well.
Anyone know of a work around short of the custom control as outlined in the KB article?
Something else going on I've missed?
Looking at it more closely the SplitContainer is the control not resizing/honoring the anchors.
I tried running this code after the tab was shown and it didn't work - looks about the same as using anchors. It seems that the TabControl is reporting an incorrect ClientSize
SplitContainer1.Width = TabControl1.ClientSize.Width - 10
SplitContainer1.Height = TabControl1.ClientSize.Height - TabControl1.ItemSize.Height - 10
Here is a complete form that shows the problem. On a 125% desktop it shows as in the IDE on a 100% desktop the controls on the tab are not positioned properly.
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frmChild
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<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
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.TabControl1 = New System.Windows.Forms.TabControl()
Me.TabPage1 = New System.Windows.Forms.TabPage()
Me.SplitContainer1 = New System.Windows.Forms.SplitContainer()
Me.Button1 = New System.Windows.Forms.Button()
Me.TabPage2 = New System.Windows.Forms.TabPage()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.Button2 = New System.Windows.Forms.Button()
Me.TabControl1.SuspendLayout()
Me.TabPage1.SuspendLayout()
CType(Me.SplitContainer1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SplitContainer1.Panel1.SuspendLayout()
Me.SplitContainer1.Panel2.SuspendLayout()
Me.SplitContainer1.SuspendLayout()
Me.SuspendLayout()
'
'TabControl1
'
Me.TabControl1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.TabControl1.Controls.Add(Me.TabPage1)
Me.TabControl1.Controls.Add(Me.TabPage2)
Me.TabControl1.Location = New System.Drawing.Point(82, 2)
Me.TabControl1.Name = "TabControl1"
Me.TabControl1.SelectedIndex = 0
Me.TabControl1.Size = New System.Drawing.Size(466, 436)
Me.TabControl1.TabIndex = 2
'
'TabPage1
'
Me.TabPage1.Controls.Add(Me.SplitContainer1)
Me.TabPage1.Location = New System.Drawing.Point(4, 25)
Me.TabPage1.Name = "TabPage1"
Me.TabPage1.Padding = New System.Windows.Forms.Padding(3)
Me.TabPage1.Size = New System.Drawing.Size(458, 407)
Me.TabPage1.TabIndex = 0
Me.TabPage1.Text = "TabPage1"
Me.TabPage1.UseVisualStyleBackColor = True
'
'SplitContainer1
'
Me.SplitContainer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.SplitContainer1.Dock = System.Windows.Forms.DockStyle.Fill
Me.SplitContainer1.Location = New System.Drawing.Point(3, 3)
Me.SplitContainer1.Name = "SplitContainer1"
Me.SplitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal
'
'SplitContainer1.Panel1
'
Me.SplitContainer1.Panel1.Controls.Add(Me.Button2)
Me.SplitContainer1.Panel1.Controls.Add(Me.TextBox1)
'
'SplitContainer1.Panel2
'
Me.SplitContainer1.Panel2.Controls.Add(Me.Button1)
Me.SplitContainer1.Size = New System.Drawing.Size(452, 401)
Me.SplitContainer1.SplitterDistance = 223
Me.SplitContainer1.TabIndex = 0
'
'Button1
'
Me.Button1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.Button1.Location = New System.Drawing.Point(371, 146)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
Me.Button1.UseVisualStyleBackColor = True
'
'TabPage2
'
Me.TabPage2.Location = New System.Drawing.Point(4, 25)
Me.TabPage2.Name = "TabPage2"
Me.TabPage2.Padding = New System.Windows.Forms.Padding(3)
Me.TabPage2.Size = New System.Drawing.Size(854, 450)
Me.TabPage2.TabIndex = 1
Me.TabPage2.Text = "TabPage2"
Me.TabPage2.UseVisualStyleBackColor = True
'
'TextBox1
'
Me.TextBox1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.TextBox1.BackColor = System.Drawing.SystemColors.Info
Me.TextBox1.Location = New System.Drawing.Point(17, 13)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.TextBox1.Size = New System.Drawing.Size(344, 177)
Me.TextBox1.TabIndex = 0
'
'Button2
'
Me.Button2.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.Button2.Location = New System.Drawing.Point(371, 195)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(75, 23)
Me.Button2.TabIndex = 1
Me.Button2.Text = "Button2"
Me.Button2.UseVisualStyleBackColor = True
'
'frmChild
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(120.0!, 120.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi
Me.ClientSize = New System.Drawing.Size(548, 439)
Me.Controls.Add(Me.TabControl1)
Me.Name = "frmChild"
Me.Text = "frmChild"
Me.TabControl1.ResumeLayout(False)
Me.TabPage1.ResumeLayout(False)
Me.SplitContainer1.Panel1.ResumeLayout(False)
Me.SplitContainer1.Panel1.PerformLayout()
Me.SplitContainer1.Panel2.ResumeLayout(False)
CType(Me.SplitContainer1, System.ComponentModel.ISupportInitialize).EndInit()
Me.SplitContainer1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
Friend WithEvents TabControl1 As System.Windows.Forms.TabControl
Friend WithEvents TabPage1 As System.Windows.Forms.TabPage
Friend WithEvents SplitContainer1 As System.Windows.Forms.SplitContainer
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TabPage2 As System.Windows.Forms.TabPage
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
End Class
If the SplitPanel isn't anchoring its contents correctly, you could try putting the contents into another container that is less buggy.
Try putting a TableLayoutPanel inside the SplitPanel. Set the TableLayoutPanel.Dock property to Fill, and then .Anchor your controls inside that. (Don't use .Dock inside a TableLayoutPanel, it's a bit flaky).
The controls inside the TableLayoutPanel will have new properties called .RowSpan and .ColumnSpan which allow the controls to span multiple cells.
There is a little arrow in the top right of the TableLayoutPanel that will allow you to edit the rows and columns. I find the best is to make as many as possible fixed width/height and then use percentage for the rest. I don't use Autosize but you could try that.
I'm experiencing a problem with the datagridview. I'm trying to create a program that allows me to run certain tests. I want to list them in a datagridview. Then with a counter I want the program to go through the active serverprocesses and run them. In the overview I want to visualize whether a process is active by coloring a cell that i add. I've done this before and used the same code but this time it doesn't seem to work. You can find my code for the load event of the form here. Can anyone tell me what I'm doing wrong?
Private Sub frmServerProcesses_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim strSQL As String
Dim oDR As SqlClient.SqlDataReader = Nothing
'bij het opstarten moet de stopknop disabled zijn
btnServerStop.Enabled = False
btnServerStart.Enabled = True
statServerProcesseslbl.Text = "Server ready"
'opvragen van de processen
strSQL = " SELECT * FROM SERVERPROCESSES"
Dim connection As New SqlConnection(SQLConnectstring)
Dim dataadapter As New SqlDataAdapter(strSQL, connection)
Dim ds As New DataSet()
connection.Open()
dataadapter.Fill(ds, "SERVERPROCESSES")
connection.Close()
dgvServerProcesses.DataSource = ds
dgvServerProcesses.DataMember = "SERVERPROCESSES"
dgvServerProcesses.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
dgvServerProcesses.Columns("LASTRUNDATE").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
'lege row die normaal wordt toegevoegd verwijderen
dgvServerProcesses.AllowUserToAddRows = False
'extra kolom toevoegen voor kleuren van actief of niet
dgvServerProcesses.Columns.Add("TEST", "TEST")
For i As Integer = 1 To dgvServerProcesses.Rows.Count - 1
If dgvServerProcesses.Rows(i).Cells(2).Value = "True" Then
dgvServerProcesses.Rows(i).Cells(2).Style.BackColor = Color.Black
End If
Next
'lege row die normaal wordt toegevoegd verwijderen
dgvServerProcesses.AllowUserToAddRows = False
End Sub
I've just tried to put both things in separate subs. So filling up the grid and marking the active ones are separate now. Both subs are called by the load sub. But still the colors don't work. But if I call the checkprocess with a button it does work. But what is also very strange is that the columncount is different. If I call it with a button he starts counting on 1 in the other case on 0. Can someone explain that to me? My new code to check the active boolean is shown here
Public Sub CheckProcessActive()
For i As Integer = 0 To dgvServerProcesses.Rows.Count - 1
If dgvServerProcesses.Rows(i).Cells(2).Value = "True" Then
dgvServerProcesses.Rows(i).Cells("ACTIVE").Style.BackColor = Color.Green
Else
dgvServerProcesses.Rows(i).Cells("ACTIVE").Style.BackColor = Color.Red
End If
Next
End Sub
The behavior you have noticed is normal. Even if you set the DataSource property, the DatagridView won't create columns and be populated until the grid is displayed, it's not populated immediately after setting this property.
You can use the DataGridView.DataBindingComplete event to be sure the grid is populated when you change the style and call CheckProcessActive() here.
i am trying to make a new tab and my new tabs always have a space between them
im new to this site so i cant post pictures so heres a link to my issue http://i43.tinypic.com/rbbndk.png
heres my new tab code
Private Sub NewPageToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NewPageToolStripMenuItem.Click
Dim newpage As TabItem = TabControl1.CreateTab("newpage")
Dim textb As New RichTextBox
Dim filename As New TextBox
Dim sw As New StreamWriter(siteloc & filename.Text & ".hsp")
Dim createb As New Button
'Set the contents of the page
textb.ReadOnly = False
textb.Multiline = True
textb.Dock() = DockStyle.Top
textb.Height = 338
newpage.Text = "NewPage"
filename.Text = "Untitled"
filename.Location = New Point(5, 342)
filename.Width = 220
createb.Location = New Point(232, 342)
createb.Text = "Submit page"
'Add the tab to the page
newpage.AttachedControl.Controls.Add(filename)
newpage.AttachedControl.Controls.Add(textb)
newpage.AttachedControl.Controls.Add(createb)
TabControl1.Tabs.Add(newpage)
'select the tab
TabControl1.SelectedTab = newpage
'add button handlers
AddHandler createb.Click, AddressOf createb_Click
End Sub
i looked all over for answers and found nothing. i havent changed anything in the propertys and i just installed dotnetbar.
CreateTab method already adds the newly created tab to Tabs collection (see docs for the method) so you are adding it twice. Remove this code: TabControl1.Tabs.Add(newpage)
Hope this helps.
I have a child form that is completely created in code.
I would like to add tool tips to the textbox controls on the form. I know how to set up the tool tips on the fly but can't find a way to add the tooltip control to the form on the fly. All the hits I find on google refer to dragging the control from the designers toolbox.
I would need to do something like:
' Add tool tip control
Dim toolTip1 As New ToolTip()
toolTip1.ShowAlways = True
frm.Controls.Add(toolTip1)
This does not work
I tried adding a sub to handle the from.load event(with a handler that poitn to the sub) at design time but can not get passed the error "Tooltip1 is not declared" when adding the tooltip to the iundividual dynamic controls.
If I call this dynamic form from a parent form and add the tooltip control to the parent form I can use it for the child form. But how would I do this if I was creating the form from a routine that does not live on a parent form?
thanks
Dim frm As New Form
' Add tool tip control
''Dim toolTip1 As New ToolTip()
''toolTip1.ShowAlways = True
'Draw the Form object
'close the dynamic frm if existing already
If frm IsNot Nothing Then
frm.Close()
End If
frm = New Form()
frm.AutoScaleDimensions = New System.Drawing.SizeF(6.0F, 13.0F)
frm.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
frm.Name = "frm_test"
'dimension is irrelevant at the moment
frm.ClientSize = New System.Drawing.Size(10, 10)
'the parent will be the current form
'frm.MdiParent = this;
'splash screen mode form, why not...
frm.ControlBox = True
frm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
frm.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink
frm.BackColor = System.Drawing.Color.LightGray
For Each item As MYFILE.Class in the Collection
Dim aTextBox As New TextBox()
aTextBox.Font = New System.Drawing.Font(sFont, Single.Parse(sSizeFont), System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CByte(0))
aTextBox.BackColor = System.Drawing.Color.Yellow
aTextBox.Location = New System.Drawing.Point(iNewColumnPosition + 5 + intMaxWidthLabel, intVertPos)
aTextBox.Size = New System.Drawing.Size(intWidthTextBox + 10, intGapHeight)
'store the biggest width, so that the textboxes can be vertically aligned
If intWidthTextBox > intMaxWidthText Then
intMaxWidthText = intWidthTextBox
End If
'giving a name to all your object will be the only way
'to retrieve them and use them
'for the purpose of this sample, the name can be the
'same for all textboxes.
aTextBox.Name = item.ParameterName
'giving the maximun size in caracters for the textbox.
aTextBox.MaxLength = Integer.Parse(item.ParameterLength)
toolTip1.SetToolTip(aTextBox, "TIP" & intIndex.ToString)
'tab have to be ordered
aTextBox.TabIndex = intIndex
intIndex += 1
'Vertical position is to be manage according the
'tallest object in the form, in this case the
'textbox it self
intVertPos += intGapHeight
'adding the textbox to the form
frm.SuspendLayout()
aTextBox.SuspendLayout()
frm.Controls.Add(aTextBox)
Next
I left a lot of code out but this should give you an idea as to what I am doing
In vb it is
Dim tooltip As New ToolTip(components)
tooltip.SetToolTip(textBox1, "This is a textbox tooltip")
Sorry this is not in VB.NET but I am pretty sure you can easily convert this. The first line is to set ToolTip control to your form components. The second is how you set a tooltip to a control and give it the related text.
ToolTip tooltip = new ToolTip(components);
tooltip.SetToolTip(textBox1, "This is a textbox tooltip");