I try to achive a label member rectangle output through a textfile databindings listbox.

Štefan Mihael Rihar 181 Reputation points
2022-11-13T22:12:37.067+00:00

project StainelessCopyCat ClassFile KuhStab
For me, stumbling upon conventions not only naming conventions was not enough
to read the documentations without headaches.

Still i am not able to pinpoint how to add one, custom, member to a property environment,
a controls property content is above in a text file link, (member?)
in an label control class, instance.
project StainelessCopyCat ClassFile Form1

Somewhere i saw, the invalidate keyword is used for repainting only
a part of the or a control.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,632 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Jiachen Li-MSFT 27,666 Reputation points Microsoft Vendor
    2022-11-14T06:41:20.25+00:00

    Hi @Štefan Mihael Rihar ,
    You can try something like this to paint a rectangle in the label.

        Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)  
            e.Graphics.DrawRectangle(Pens.Red, 50, 50, 50, 50)  
        End Sub  
    

    Best Regards.
    Jiachen Li

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. LesHay 7,126 Reputation points
    2022-12-07T02:06:34.927+00:00

    Hi
    I am not sure if I understand your question, but it seems you want to apply control style properties from text (file) input.
    Here is some code that sets up a few random controls and applies property values from strings (could be from file, but this example just uses dictionaries)

    The idea here is that a control has an associated dictionary with the property name as the key and the property value(s) as a string.

    In this example, there is a Label, Listbox1 and a ListBox2, each with some properties set by strings from the respective dictionary. (just as easy with text from a database/file whatever)

    If this example is not relevant to your question, just ignore it.

    267928-111.png

    Option Strict On  
    Option Explicit On  
    Public Class Form1  
      Dim WithEvents MyListBox1 As New ListBox  
      Dim WithEvents MyListBox2 As New ListBox  
      Dim MyLabel As New Label  
      Dim listbox1dic As New Dictionary(Of String, String)  
      Dim listbox2dic As New Dictionary(Of String, String)  
      Dim labdic As New Dictionary(Of String, String)  
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load  
        With labdic  
          .Add("Location", "50,50")  
          .Add("Text", "Freddy wuz heer")  
          .Add("AutoSize", "False")  
          .Add("Size", "120,40")  
          .Add("BackColor", "150,255,170,150")  
        End With  
        With listbox1dic  
          .Add("Location", "250,10")  
          .Add("Size", "180,340")  
          .Add("BackColor", "255,160,170,255")  
        End With  
        With listbox2dic  
          .Add("Location", "450,10")  
          .Add("Size", "180,340")  
          .Add("BackColor", "255,160,255,170")  
        End With  
      
        With MyListBox1  
          .MultiColumn = True  
          .ColumnWidth = 180  
          .DataSource = New BindingSource(listbox1dic, String.Empty)  
      
          .Location = GetLoc(listbox1dic("Location"))  
          .BackColor = GetColor(listbox1dic("BackColor"))  
          .Size = GetSize(listbox1dic("Size"))  
        End With  
        With MyListBox2  
          .MultiColumn = True  
          .ColumnWidth = 180  
          .DataSource = New BindingSource(listbox2dic, String.Empty)  
      
          .Location = GetLoc(listbox2dic("Location"))  
          .BackColor = GetColor(listbox2dic("BackColor"))  
          .Size = GetSize(listbox2dic("Size"))  
        End With  
        With MyLabel  
          .Text = labdic("Text")  
          .BackColor = GetColor(labdic("BackColor"))  
          .Location = GetLoc(labdic("Location"))  
          .AutoSize = CBool(labdic("AutoSize"))  
          .Size = GetSize(labdic("Size"))  
        End With  
        Controls.AddRange({MyLabel, MyListBox1, MyListBox2})  
      End Sub  
      Function GetColor(s As String) As Color  
        Return Color.FromArgb(GetInteger(s.Split(","c)(0)), GetInteger(s.Split(","c)(1)), GetInteger(s.Split(","c)(2)), GetInteger(s.Split(","c)(3)))  
      End Function  
      Function GetLoc(s As String) As Point  
        Return New Point(GetInteger(s.Split(","c)(0)), GetInteger(s.Split(","c)(1)))  
      End Function  
      Function GetSize(s As String) As Size  
        Return New Size(GetInteger(s.Split(","c)(0)), GetInteger(s.Split(","c)(0)))  
      End Function  
      Function GetInteger(s As String) As Integer  
        Dim v As Integer = 0  
        Integer.TryParse(s, v)  
        Return v  
      End Function  
    End Class