panel location is changed after set it's height

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
I have a normal panel and a datagridview in it.
I set some class values and finally I set the panel height.
But if the panel height is greater than the form height, the panel position goes wrong. If I print the location.y of the panel bevor and after setting the height, I get the same value. But in the second case the panel is elsewhere positioned. Why???
Here the panel class:
<pre class="prettyprint lang-vb Option Strict On
Public Class datapanel
Inherits System.Windows.Forms.Panel
Structure szovegek
Dim szoveg1 As String
Dim szoveg2 As String
Dim szoveg3 As String
Dim pos1 As Integer
Dim pos2 As Integer
Dim pos3 As Integer
Dim y As Integer
End Structure
Dim szovegsorok As List(Of szovegek)
Dim felirat As Label
Const elsofeliratszin As Integer = 8666368
Dim tabla As datatable
Dim tbx, tby As Integer
Public Sub New()
MyBase.New()
Me.BorderStyle = Windows.Forms.BorderStyle.FixedSingle
Me.BackColor = Color.FromKnownColor(KnownColor.Control)
End Sub
Public Property feliratok() As List(Of szovegek)
Get
Return szovegsorok
End Get
Set(ByVal value As List(Of szovegek))
szovegsorok = value
If IsNothing(szovegsorok) Then Exit Property
For i = 0 To szovegsorok.Count - 1
1.
felirat = New Label
felirat.Text = szovegsorok(i).szoveg1
felirat.Font = New Font("calibri", 10)
felirat.AutoSize = True
felirat.ForeColor = Drawing.ColorTranslator.FromOle(elsofeliratszin)
Me.Controls.Add(felirat)
felirat.Location = New Point(szovegsorok(i).pos1, szovegsorok(i).y)
2.
felirat = New Label
felirat.Text = szovegsorok(i).szoveg2
felirat.Font = New Font("calibri", 10)
felirat.AutoSize = True
Me.Controls.Add(felirat)
felirat.Location = New Point(szovegsorok(i).pos2, szovegsorok(i).y)
3.
felirat = New Label
felirat.Text = szovegsorok(i).szoveg3
felirat.Font = New Font("calibri", 10)
felirat.AutoSize = True
Me.Controls.Add(felirat)
felirat.Location = New Point(szovegsorok(i).pos3, szovegsorok(i).y)
Next
End Set
End Property
Public Property tabla_x() As Integer
Get
Return tbx
End Get
Set(ByVal value As Integer)
tbx = value
End Set
End Property
Public Property tabla_y() As Integer
Get
Return tby
End Get
Set(ByVal value As Integer)
tby = value
End Set
End Property
Public Property adattabla() As datatable
Get
Return tabla
End Get
Set(ByVal value As datatable)
tabla = value
If IsNothing(tabla) Then Exit Property
Me.Controls.Add(tabla)
tabla.Location = New Point(tbx, tby)
End Set
End Property
End Class
[/code]
here the dgv class:
<pre class="prettyprint lang-vb Option Strict On
Public Class datatable
Inherits Windows.Forms.DataGridView
Dim p1 As Pen
Dim brs As SolidBrush
Dim sorm As Integer
Const tablahatter As Integer = 15391691
Const fejlechatter As Integer = 16632669
Const paratlansor As Integer = 16644590
Const parossor As Integer = 16051415
Public Sub New()
MyBase.New()
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.ResizeRedraw, True)
Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
Me.AllowUserToAddRows = False
Me.AllowUserToDeleteRows = False
Me.EditMode = DataGridViewEditMode.EditProgrammatically
Me.RowHeadersVisible = False
Me.BorderStyle = Windows.Forms.BorderStyle.None
Me.Font = New Font("calibri", 9)
Me.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
Me.ScrollBars = Windows.Forms.ScrollBars.None
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
szélek
p1 = New Pen(Color.Black, 1)
e.Graphics.DrawLine(p1, 0, 0, 0, Height - 1)
e.Graphics.DrawLine(p1, 0, 0, Width - 1, 0)
e.Graphics.DrawLine(p1, Width - 1, 0, Width - 1, Height - 1)
e.Graphics.DrawLine(p1, 0, Height - 1, Width - 1, Height - 1)
End Sub
Protected Overrides Sub PaintBackground(ByVal graphics As System.Drawing.Graphics, ByVal clipBounds As System.Drawing.Rectangle, ByVal gridBounds As System.Drawing.Rectangle)
graphics.FillRectangle(New SolidBrush(Color.FromKnownColor(KnownColor.Control)), clipBounds)
End Sub
Protected Overrides Sub OnCellPainting(ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs)
MyBase.OnCellPainting(e)
fejléc
If e.RowIndex = -1 Then
Dim rect As Rectangle = e.CellBounds
háttér
brs = New SolidBrush(Drawing.ColorTranslator.FromOle(fejlechatter))
e.Graphics.FillRectangle(brs, rect.Left + 5, rect.Top + 8, rect.Width - 8, rect.Bottom - 18)
e.PaintContent(rect)
keret
p1 = New Pen(Color.Black, 1)
e.Graphics.DrawLine(p1, rect.Left, rect.Bottom - 6, rect.Right - 1, rect.Bottom - 6)
e.Graphics.DrawLine(p1, rect.Right, rect.Top, rect.Right, rect.Bottom - 6)
End If
többi sor
If e.RowIndex >= 0 Then
e.CellStyle.Padding = New Padding(3, 0, 0, 0)
e.Paint(e.CellBounds, DataGridViewPaintParts.All Xor DataGridViewPaintParts.Border Xor DataGridViewPaintParts.ContentBackground)
Dim rect As Rectangle = e.CellBounds
keret
p1 = New Pen(Color.Black, 1)
bal
If e.ColumnIndex > 0 Then e.Graphics.DrawLine(p1, rect.Left, rect.Top - 5, rect.Left, rect.Bottom - 1)
jobb
e.Graphics.DrawLine(p1, rect.Right, rect.Top - 5, rect.Right, rect.Bottom - 1)
If e.RowIndex = Me.RowCount - 1 Then
bal
If e.ColumnIndex > 0 Then e.Graphics.DrawLine(p1, rect.Left, rect.Top - 5, rect.Left, rect.Bottom + Me.Height - Me.ColumnHeadersHeight)
jobb
e.Graphics.DrawLine(p1, rect.Right, rect.Top - 5, rect.Right, rect.Bottom + Me.Height - Me.ColumnHeadersHeight)
End If
cellák háttere
Me.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.BackColor = Color.FromKnownColor(KnownColor.Control)
If e.RowIndex Mod 2 <> 0 Then
háttér
brs = New SolidBrush(Drawing.ColorTranslator.FromOle(paratlansor))
e.Graphics.FillRectangle(brs, rect.Left + 5, rect.Top, rect.Width - 8, 19)
e.PaintContent(rect)
End If
If e.RowIndex Mod 2 = 0 Then
háttér
brs = New SolidBrush(Drawing.ColorTranslator.FromOle(parossor))
e.Graphics.FillRectangle(brs, rect.Left + 5, rect.Top, rect.Width - 8, 19)
e.PaintContent(rect)
End If
End If
e.Handled = True
End Sub
Protected Overrides Sub OnColumnAdded(ByVal e As System.Windows.Forms.DataGridViewColumnEventArgs)
MyBase.OnColumnAdded(e)
Me.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
Me.EnableHeadersVisualStyles = False
Me.ColumnHeadersHeight = 35
e.Column.Resizable = DataGridViewTriState.False
End Sub
Protected Overrides Sub OnSelectionChanged(ByVal e As System.EventArgs)
MyBase.OnSelectionChanged(e)
If Me.SelectedCells.Count > 0 Then Me.SelectedCells(0).Selected = False
End Sub
End Class
[/code]
and here the form load event:
<pre class="prettyprint lang-vb Dim feliratok As New List(Of datapanel.szovegek)
Dim egysor As New datapanel.szovegek

egysor.szoveg1 = "Főkönyvi számla"
egysor.pos1 = 10
egysor.szoveg2 = "751300"
egysor.pos2 = 150
egysor.szoveg3 = "cash pool kamatráfordítás"
egysor.pos3 = 250
egysor.y = 10

feliratok.Add(egysor)

egysor = Nothing

egysor.szoveg1 = "Vállalat"
egysor.pos1 = 10
egysor.szoveg2 = "5000"
egysor.pos2 = 150
egysor.szoveg3 = ""
egysor.pos3 = 250
egysor.y = 25

feliratok.Add(egysor)

Datapanel1.feliratok = feliratok

Dim tabla As New datatable
tabla.Columns.Add("Tétel", "Tétel")
tabla.Columns.Add("Szöveg", "Szöveg")
tabla.Columns.Add("Dátum", "Dátum")
tabla.Columns.Add("Biz. fajta", "Biz. fajta")
tabla.Columns.Add("Összeg", "Összeg")
tabla.Columns(0).Width = 50
tabla.Columns(1).Width = 300
tabla.Columns(2).Width = 80
tabla.Columns(3).Width = 100
tabla.Columns(4).Width = 150
tabla.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
tabla.Width = 680

For i = 0 To 50
tabla.Rows.Add(i.ToString, "teszt szöveg " & i.ToString, DateAdd(DateInterval.Day, i, Now).ToShortDateString, "FK", _
GroupNumbs(i * 250350, ""))
Next

tabla.Height = 35 + tabla.RowCount * 20

Datapanel1.tabla_x = 10
Datapanel1.tabla_y = 70
Datapanel1.adattabla = tabla
<span style="text-decoration:underline Datapanel1.Height = Datapanel1.tabla_y + Datapanel1.adattabla.Height [/code]
<br/>
Im talking about the underlined line.


View the full article
 
Back
Top