problem positioning controls

alaric

Well-known member
Joined
Oct 12, 2005
Messages
53
Programming Experience
Beginner
Hi,

When loading my form I want to position a tabcontrol depending of the width of a datagrid.

I do (on the form load event)
VB.NET:
[COLOR=#008000]
'load the list
[/COLOR]LoadList()
[COLOR=#008000]
[/COLOR][COLOR=#008000]'add TableSyle
[/COLOR]tsCursistenInschrijvingen()
[COLOR=#008000]'calc our start coordinates X and Y AFTER we added the ts
[/COLOR][COLOR=#0000ff]Dim[/COLOR] intX [COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]Integer[/COLOR] = [COLOR=#0000ff]Me[/COLOR].dgCursisten.Location.X + ([COLOR=#0000ff]Me[/COLOR].dgCursisten.Width)
[COLOR=#0000ff]Dim[/COLOR] intY [COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]Integer[/COLOR] = [COLOR=#0000ff]Me[/COLOR].dgCursisten.Location.Y
 
[COLOR=#008000]'set new position of tabcontrol
[/COLOR][COLOR=#0000ff]Me[/COLOR].TabControl1.Location = [COLOR=#0000ff]New[/COLOR] Point(intX, intY)


so, the tabcontrol should be on the same height as the datagrid. But its always a lot lower??

When I calc the values in the command window
?adresboekfrm.dgCursisten.Location.X + adresboekfrm.dgCursisten.Width --> 613
?adresboekfrm.dgCursisten.Location --> 107, 144
?adresboekfrm.TabControl1.Location --> 613 , 144

so, this means (to me) that according to the values, the tabcontrol is directly attached to the upperright corner of the datagrid. But in my for it is NOT??

Anyone ideas? what's the thing I'm doing wrong here?

thanks in advance
 
would this not work(on load)?
tabcontrol.left = 0
tabcontrol.top = 0
tabcontrol.width = form1.width

EDIT: Sorry I misread your question, my apologies.
 
Thanks to you all, for replying,

a demo is kind a hard. everything is based on MSDE. I will make one if nothing else seems to work.
To make things easier to understand, I attached a screenshot. as you can.. my problem.

this is the load event;
VB.NET:
[SIZE=2][COLOR=#0000ff]
Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] frmAdresboek_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load
[/SIZE][SIZE=2][COLOR=#008000]'make mouse hourglass
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Cursor = Cursors.WaitCursor
[/SIZE][SIZE=2][COLOR=#008000]'find desktop resolution
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'DisplayResolution(frm1)
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] frmWorkingArea [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Form
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] rctWorkingarea [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Rectangle
rctWorkingarea = Screen.PrimaryScreen.GetWorkingArea(frmWorkingArea)
frmWorkingArea.Close()
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Top = 0
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Left = 0
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Width = rctWorkingarea.Width()
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Height = rctWorkingarea.Height()
UsrCMenu1.btnAdresboek.Enabled = [/SIZE][SIZE=2][COLOR=#0000ff]False
[/COLOR][/SIZE]
[SIZE=2]ActivateEditing([/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE][SIZE=2])
[/SIZE]
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'load the list
[/COLOR][/SIZE][SIZE=2]LoadList()
[/SIZE]
 
[SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'add TableSyle
[/COLOR][/SIZE][SIZE=2]tsCursistenInschrijvingen()
 
[/SIZE][SIZE=2][COLOR=#008000]'calc our start coordinates X and Y
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] intX [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].dgCursisten.Location.X + ([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].dgCursisten.Width)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] intY [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].dgCursisten.Location.Y[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#008000]'Me.dgCursisten.TableStyles.Add(tsCursistenInschr)
[/COLOR][/SIZE][SIZE=2]Console.WriteLine("adresboek load")
Console.WriteLine([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].dgCursisten.Location)
Console.WriteLine([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].dgCursisten.Width)[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#008000]'set new position of tabcontrol
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].TabControl1.Location = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Point(intX, intY)
Console.WriteLine([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].TabControl1.Location)
dgCursisten.DataSource = dtCursisten
cmCursisten = [/SIZE][SIZE=2][COLOR=#0000ff]DirectCast[/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].dgCursisten.BindingContext(dtCursisten), CurrencyManager)
SetDataViewFilter("")
 
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].btnAll.BackColor = Color.Orange
[/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Cursor = Cursors.Default
 
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]

this is my tablestyle:
VB.NET:
[SIZE=2][COLOR=#0000ff]
Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] tsCursistenInschrijvingen()
[/SIZE][SIZE=2][COLOR=#008000]'Dim tsCursistenInschr As DataGridTableStyle
[/COLOR][/SIZE][SIZE=2]tsCursistenInschr = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataGridTableStyle
tsCursistenInschr.RowHeadersVisible = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]tsCursistenInschr.SelectionBackColor = Color.Orange
tsCursistenInschr.BackColor = SystemColors.Info
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] colCount [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = 0
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] dgCursWidth [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = 0[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#008000]'add column 1 == Totaal === string CursistID
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] TextCol [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataGridTextBoxColumn
TextCol = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataGridTextBoxColumn
TextCol.Alignment = System.Windows.Forms.HorizontalAlignment.Left
TextCol.FormatInfo = [/SIZE][SIZE=2][COLOR=#0000ff]Nothing
[/COLOR][/SIZE][SIZE=2]TextCol.HeaderText = "CursistID"
TextCol.MappingName = "CursistId"
TextCol.NullText = ""
TextCol.ReadOnly = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]TextCol.Width = 0
tsCursistenInschr.GridColumnStyles.Add(TextCol)
colCount = (colCount + 1)
dgCursWidth = dgCursWidth + TextCol.Width
 
[/SIZE][SIZE=2][COLOR=#008000]'add column 2 == Totaal === string Name
[/COLOR][/SIZE][SIZE=2]TextCol = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataGridTextBoxColumn
TextCol.Alignment = System.Windows.Forms.HorizontalAlignment.Left
TextCol.FormatInfo = [/SIZE][SIZE=2][COLOR=#0000ff]Nothing
[/COLOR][/SIZE][SIZE=2]TextCol.HeaderText = "Naam"
TextCol.MappingName = "Naam"
TextCol.NullText = ""
TextCol.ReadOnly = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]TextCol.Width = 150
tsCursistenInschr.GridColumnStyles.Add(TextCol)
colCount = (colCount + 1)
dgCursWidth = dgCursWidth + TextCol.Width
 
[/SIZE][SIZE=2][COLOR=#008000]'add column 3 == Totaal === string Adres
[/COLOR][/SIZE][SIZE=2]TextCol = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataGridTextBoxColumn
TextCol.Alignment = System.Windows.Forms.HorizontalAlignment.Left
TextCol.FormatInfo = [/SIZE][SIZE=2][COLOR=#0000ff]Nothing
[/COLOR][/SIZE][SIZE=2]TextCol.HeaderText = "Adres"
TextCol.MappingName = "Adres"
TextCol.NullText = ""
TextCol.ReadOnly = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]TextCol.Width = 190
tsCursistenInschr.GridColumnStyles.Add(TextCol)
colCount = (colCount + 1)
dgCursWidth = dgCursWidth + TextCol.Width
 
[/SIZE][SIZE=2][COLOR=#008000]'add column 4 == Totaal === string Woonplaats
[/COLOR][/SIZE][SIZE=2]TextCol = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataGridTextBoxColumn
TextCol.Alignment = System.Windows.Forms.HorizontalAlignment.Left
TextCol.FormatInfo = [/SIZE][SIZE=2][COLOR=#0000ff]Nothing
[/COLOR][/SIZE][SIZE=2]TextCol.HeaderText = "Woonplaats"
TextCol.MappingName = "Woonplaats"
TextCol.NullText = ""
TextCol.ReadOnly = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]TextCol.Width = 110
tsCursistenInschr.GridColumnStyles.Add(TextCol)
colCount = (colCount + 1)
dgCursWidth = dgCursWidth + TextCol.Width
 
[/SIZE][SIZE=2][COLOR=#008000]'add column 5 == Totaal === string Actief
[/COLOR][/SIZE][SIZE=2]TextCol = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataGridTextBoxColumn
TextCol.Alignment = System.Windows.Forms.HorizontalAlignment.Left
TextCol.FormatInfo = [/SIZE][SIZE=2][COLOR=#0000ff]Nothing
[/COLOR][/SIZE][SIZE=2]TextCol.HeaderText = ""
TextCol.MappingName = "Actief"
TextCol.NullText = ""
TextCol.ReadOnly = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]TextCol.Width = 0
tsCursistenInschr.GridColumnStyles.Add(TextCol)
colCount = (colCount + 1)
dgCursWidth = dgCursWidth + TextCol.Width
 
[/SIZE][SIZE=2][COLOR=#008000]'add column 6 == Totaal === string Student
[/COLOR][/SIZE][SIZE=2]TextCol = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataGridTextBoxColumn
TextCol.Alignment = System.Windows.Forms.HorizontalAlignment.Left
TextCol.FormatInfo = [/SIZE][SIZE=2][COLOR=#0000ff]Nothing
[/COLOR][/SIZE][SIZE=2]TextCol.HeaderText = ""
TextCol.MappingName = "Student"
TextCol.NullText = ""
TextCol.ReadOnly = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]TextCol.Width = 0
tsCursistenInschr.GridColumnStyles.Add(TextCol)
colCount = (colCount + 1)
dgCursWidth = dgCursWidth + TextCol.Width
 
[/SIZE][SIZE=2][COLOR=#008000]'add column 7 == Totaal === string Card
[/COLOR][/SIZE][SIZE=2]TextCol = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataGridTextBoxColumn
TextCol.Alignment = System.Windows.Forms.HorizontalAlignment.Left
TextCol.FormatInfo = [/SIZE][SIZE=2][COLOR=#0000ff]Nothing
[/COLOR][/SIZE][SIZE=2]TextCol.HeaderText = ""
TextCol.MappingName = "Card"
TextCol.NullText = ""
TextCol.ReadOnly = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]TextCol.Width = 0
tsCursistenInschr.GridColumnStyles.Add(TextCol)
colCount = (colCount + 1)
dgCursWidth = dgCursWidth + TextCol.Width
 
[/SIZE][SIZE=2][COLOR=#008000]'add column 8 == Totaal === string BAnkrekening
[/COLOR][/SIZE][SIZE=2]TextCol = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataGridTextBoxColumn
TextCol.Alignment = System.Windows.Forms.HorizontalAlignment.Left
TextCol.FormatInfo = [/SIZE][SIZE=2][COLOR=#0000ff]Nothing
[/COLOR][/SIZE][SIZE=2]TextCol.HeaderText = ""
TextCol.MappingName = "Bankrekening"
TextCol.NullText = ""
TextCol.ReadOnly = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]TextCol.Width = 0
tsCursistenInschr.GridColumnStyles.Add(TextCol)
colCount = (colCount + 1)
dgCursWidth = dgCursWidth + TextCol.Width
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].dgCursisten.Width = dgCursWidth + 56 [/SIZE][SIZE=2][COLOR=#008000]'56 width of rowheader
[/COLOR][/SIZE][SIZE=2]dgCursisten.TableStyles.Add(tsCursistenInschr)
[/SIZE]
 

Attachments

  • screeshot1.JPG
    screeshot1.JPG
    26.5 KB · Views: 48
Back
Top