Page 1 of 1

Drawstring with space?

Posted: Wed Feb 15, 2017 4:45 pm
by Dummy1912
Hello,

i was wondering if somebody can make us a tutorial :

we like to use some strings and then use drawstring
but when we add our texts into the strings
we like to move the other parts of the string to move a way from each other

like for example first string

Lastname Firstname Address Zip

the longer or smaller the lastname , firstname or address or other strings become the zip or other strings has to move left or right from the address or other strings away
and when some strings are empty the have to dispose and only show the other strings that are not empty have to take the places.

hope you guys get it :)

Thanks
Dummy1912

Re: Drawstring with space?

Posted: Sun Feb 19, 2017 12:01 pm
by CodenStuff
Can you explain a bit more because I'm a little confused about what it is you're trying to accomplish here :duh;

Re: Drawstring with space?

Posted: Sun Feb 19, 2017 12:07 pm
by Dummy1912
Hi :)

well as i said before and yeah i known i can be a little :errm; hahaha

lets see,
our strings must successively follow each other even there is no string value been found
then the followed string must take his place.

Is this better :D

Regards

Dummy

Re: Drawstring with space?

Posted: Sun Feb 19, 2017 1:30 pm
by CodenStuff
Are you drawing each string individually at set locations or all as one string?

What code do you have so far.

Re: Drawstring with space?

Posted: Sun Feb 19, 2017 1:36 pm
by Dummy1912
Here you go
Code: Select all
    Private _PText As String
    <Category("Appearance"),
    Description("Get or Set the description, Max. 30 Chars")>
    Public Property Description() As String
        Get
            Return _PText
        End Get
        Set(ByVal Value As String)
            _PText = Value
            Invalidate()
        End Set
    End Property

    Public MyAmount As Double
    Private _PAmount As String
    Public Property Amount() As String
        Get
            Return _PAmount
        End Get
        Set(ByVal Value As String)
            _PAmount = Value
            Invalidate()
        End Set
    End Property

    Private _PDate As String
    <Category("Appearance"),
 Description("Get or Set the date")>
    Public Property Dates() As String
        Get
            Return _PDate
        End Get
        Set(ByVal Value As String)
            _PDate = Value
            Invalidate()
        End Set
    End Property

    Private _TColor As Color
    <Category("Appearance"),
 Description("Set Order color")>
    Public Property OrderColor As Color
        Get
            Return _TColor
        End Get
        Set(value As Color)
            _TColor = value
        End Set
    End Property

    Private _Note As String
    <Category("ApplicationSettings"),
 Description("Set comments")>
    Public Property Notes As String
        Get
            Return _Note
        End Get
        Set(value As String)
            _Note = value
            Invalidate()
        End Set
    End Property

    Public MyWallet As Double
    Private _Wallet As String
    <Category("ApplicationSettings"),
 Description("Set wallet amount")>
    Public Property Wallet As String
        Get
            Return _Wallet
        End Get
        Set(value As String)
            _Wallet = value
            Invalidate()
        End Set
    End Property
Code: Select all
        With e.Graphics

            Dim _Fnt As Font = New Font("Microsoft Sans Serif", 8.25, FontStyle.Regular)
            Dim _strWd As Int32 = .MeasureString(FixStrLength(_PDate, 15), _Fnt).Width
            Dim barRect0 As New RectangleF(ImageMargin * 1, 0, _strWd + 5, Height)

            .DrawString(FixStrLength(_PDate, 15), _Fnt, New SolidBrush(Color.White), barRect0, GetStringFormat(ContentAlignment.MiddleLeft))

            'Dim _width As Int16 = 0
            'If ImageMargin * 30 > Width Then
            '    _width = ImageMargin * 8
            'Else
            '    _width = Width - ImageMargin * 630
            'End If

            _strWd = .MeasureString(FixStrLength(Amount, 10), _Fnt).Width + 30
            Dim barRect1 As New RectangleF(ImageMargin * 50, 0, _strWd + 35, Height)
            If IsEnabled Then
                .DrawString(FixStrLength(Amount, 10), _Fnt, New SolidBrush(OrderColor), barRect1, GetStringFormat(ContentAlignment.MiddleRight))
            Else
                .DrawString(FixStrLength(Amount, 10), _Fnt, New SolidBrush(Color.White), barRect1, GetStringFormat(ContentAlignment.MiddleRight))

            End If

                       _strWd = .MeasureString(FixStrLength(Notes, 35), _Fnt).Width + 30
            Dim barRect As New RectangleF(ImageMargin * 195, 0, _strWd + 35, Height)
            .DrawString(FixStrLength(Notes, 35), _Fnt, New SolidBrush(Color.White), barRect, GetStringFormat(ContentAlignment.MiddleLeft))

            _strWd = .MeasureString(FixStrLength(Description, 35), _Fnt).Width + 30
            Dim barRect2 As New RectangleF(ImageMargin * 400, 0, _strWd + 35, Height)
            .DrawString(FixStrLength(Description, 35), _Fnt, New SolidBrush(Color.White), barRect2, GetStringFormat(ContentAlignment.MiddleLeft))


            _strWd = .MeasureString(Wallet, _Fnt).Width + 30
            Dim barRect3 As New RectangleF(ImageMargin * 600, 0, _strWd + 35, Height)
            .DrawString(Wallet, _Fnt, New SolidBrush(Color.White), barRect3, GetStringFormat(ContentAlignment.MiddleLeft))
            _Fnt.Dispose()

        End With

but not really what we wanted :( the strings stay at the place even if there are no value
hope this helps to fix or a new compleet code ;)

Re: Drawstring with space?

Posted: Mon Feb 20, 2017 2:14 pm
by CodenStuff
I think I understand what you mean but I don't know if it would be simple to implement. I expect you would have to add some conditions before your drawstring code.

Could perhaps store the values and X point of each drawstring location in an array and do something like this:

(Untested and just an example)
Code: Select all
        Dim DrawLocations As New List(Of Integer)(New Integer() {195, 400, 600})

        Dim MyValues As New List(Of String)()
        'You will need to add some sort of checking to see if has a value before adding it to the array
        MyValues.Add("FirstName")
        MyValues.Add("LastName")

        For i = 0 To MyValues.Count - 1
            With e.Graphics
                _strWd = .MeasureString(FixStrLength(MyValues(i), 35), _Fnt).Width + 30
                Dim barRect2 As New RectangleF(ImageMargin * DrawLocations(i), 0, _strWd + 35, Height)
                .DrawString(FixStrLength(MyValues(i), 35), _Fnt, New SolidBrush(Color.White), barRect2, GetStringFormat(ContentAlignment.MiddleLeft))
            End With
        Next

Re: Drawstring with space?

Posted: Mon Feb 20, 2017 4:39 pm
by Dummy1912
Thanks for the example
i will check it out

what are those?
{195, 400, 600}

thanks

edit:

hmmm an error? i think with your 195,400,600
any idea?

Image

edit:

LOL i think i know the problem your have only 3 integers for 3 strings lol
and i need to add the location of the places with those integers :D
but it works till now
still need to test if no string has a value if it works or not

Re: Drawstring with space?

Posted: Mon Feb 20, 2017 5:48 pm
by Dummy1912
Hahahahahahahhahahahahahwhahahaha
so cool codenstuff

this little piece of code works like a charm
even if no string the string will move to the left where the other pieces will be
so sweet

Thanks so much
You are an angel ;)

Re: Drawstring with space?

Posted: Tue Feb 21, 2017 11:42 am
by CodenStuff
Sweet. Glad it worked for you :)