Centering Text (DButton)

How would I go about perfectly centering text in a DButton?

Thank you in advance.


But in a code, it would look like:

[lua]local DButton = vgui.Create(‘DButton’, ParentName)
DButton:SetSize(70, 25)
DButton.DoClick = function()
–function here that happens when you click it


Oh snap, misread, I thought you meant the DButton


But a DButton automatically centers the text in it,

No worries pal,
I realize it automatically centers the text. But when you use "
" in it, it will align it to the left.
I just can’t figure out how to change the alignment.

I’m not sure if there is a way, try using Multiline syntax ( thankyou MakeR :3: ) which would be

[lua]DButton:SetText( [[Line 1
Line 2]] )[/lua]

As opposed to

[lua]DButton:SetText( “Line 1
Line2” )[/lua]

Negative, still aligns it to the left.

Damn, well those are the only two options that I know, wait for someone else to read this, and i’m sure someone more experienced will know how to fix it.


The only thing I can think of is that could you use
Somewhere, because that would solve it, I just don’t know where


Well, the only other alternative is to set the text to “” and to use Surface.SetText instead and go on from there. At least, the only one I know with the ability to not fuck up the second line.

Cheers for the help, I’ll keep looking into it.

Don’t thank me, i’m just giving you solutions that don’t work :dance:

But, on a serious note, some more experienced coders, like MakeR or |FlapJack| usually lurk in these depths of Facepunch.



DButton.Paint = function(self)
derma.SkinHook( “Paint”, “Button”, self )
derma.SkinHook( “PaintOver”, “Button”, self )

	draw.SimpleText("My Button

With a new line!", “ScoreboardText”, self:GetWide()/2, self:GetTall()/2, Color(255, 255, 255, 255), 1, 1)

Using that code won’t allow for
to work.
Just tested. Makes the text “Scoreboard text” but that’s about it.
Not to worry though, I have another method around my issue that will be more user friendly.
Once again, thank you for the contributions.

Sorry, iRzilla, you just skipped my mind D: