Copyright Codenstuff.com 2017
YOU NEED TO BE LOGGED IN TO USE THIS FEATURE


Register
Credits
0
Reputation
0
Drawstring with space?
If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.


User avatar
Drawstring with space?
Drawstring with space?
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

User avatar
Re: Drawstring with space?
Re: Drawstring with space?
Can you explain a bit more because I'm a little confused about what it is you're trying to accomplish here :duh;

Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Re: Drawstring with space?
Re: Drawstring with space?
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

User avatar
Re: Drawstring with space?
Re: Drawstring with space?
Are you drawing each string individually at set locations or all as one string?

What code do you have so far.

Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Re: Drawstring with space?
Re: Drawstring with space?
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 ;)

User avatar
Re: Drawstring with space?
Re: Drawstring with space?
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

Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Re: Drawstring with space?
Re: Drawstring with space?
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

User avatar
Re: Drawstring with space?
Re: Drawstring with space?
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 ;)

User avatar
Re: Drawstring with space?
Re: Drawstring with space?
Sweet. Glad it worked for you :)

Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.



Online now

Users viewing this forum: No registered users and 1 browsing

cron