• How do I center a label in my button? xd
    9 replies, posted
Hello, usually I'm pretty good in maths but I'm still trying to Center my label in the button after 3 hours xd. I already googeld, so pls dont tell me to google for a answer. Here my code and how its looks right now: surface.CreateFont( "LabelFont1", { font = "Montserrat", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name extended = false, size = 25, weight = 500, blursize = 0, scanlines = 0, antialias = true, underline = false, italic = false, strikeout = false, symbol = false, rotary = false, shadow = false, additive = false, outline = false, } ) local frame=vgui.Create("DFrame") frame:SetSize(500,300) frame:Center() frame:SetVisible(true) frame:MakePopup() frame:ShowCloseButton(true) frame.Paint = function(s,w,h) draw.RoundedBox(0,0,0,w ,h,Color(40,40,40)) --INNEN draw.RoundedBox(0,0,0,w,25,Color(20,20,20)) end local button=vgui.Create("DButton",frame) --button send button:SetPos(5,275) button:SetSize(300,20) button:SetText("") button.Paint=function(s,w,h) draw.RoundedBox(0,0,0,w,h,Color(188, 36, 60)) end local button=vgui.Create("DButton",frame) --button close button:SetPos(310,275) button:SetSize(185,20) button:SetText("") button.Paint=function(s,w,h) draw.RoundedBox(0,0,0,w,h,Color(188, 36, 60)) end local label=vgui.Create("DLabel",frame) --label send label:SetPos(120,255) label:SetText("send") label:SetFont("LabelFont1") label:SetSize(100,60) label:SetTextColor(Color(255,255,255)) local TextEntry = vgui.Create( "DTextEntry", frame ) -- create the form as a child of frame TextEntry:SetPos( 4, 90  ) TextEntry:SetSize( 490, 180 ) TextEntry:SetText( "description" ) TextEntry.OnEnter = function( self ) chat.AddText( self:GetValue() ) -- print the form's text as server text end local label=vgui.Create("DLabel",frame) --label close label:SetPos(340,255) label:SetText("close") label:SetFont("LabelFont1") label:SetSize(100,60) label:SetTextColor(Color(255,255,255)) local DComboBox = vgui.Create( "DComboBox", frame ) DComboBox:SetPos( 5, 30 ) DComboBox:SetSize( 490, 20 ) DComboBox:SetValue( "options" ) DComboBox:AddChoice( "RDM" ) DComboBox:AddChoice( "" ) DComboBox:AddChoice( "option C" ) DComboBox.OnSelect = function( panel, index, value ) print( value .." was selected!" ) end https://files.facepunch.com/forum/upload/309258/6f4e54a3-d4b6-433c-b22a-3b9c63693bc3/Screenshot_30.png if you can help me pls explain me the math xd thx very much for help!!!
you take the height and width of the label, and make the button be in the half of that width and height, the width has to be minus the half of the button tho otherwise it will be slidly off
Use this Panel/SetContentAlignment
danke
then you used it for the frame, not your button. use your button with it
actually I just did this: local buttonsend=vgui.Create("DButton",frame) --button send buttonsend:SetPos(5,275) buttonsend:SetSize(300,20) buttonsend:SetText("") buttonsend.Paint=function(s,w,h) draw.RoundedBox(0,0,0,w,h,Color(188, 36, 60)) end local label=vgui.Create("DLabel",buttonsend) --label send label:SetContentAlignment(5) label:SetText("send") label:SetFont("LabelFont1") label:SetSize(100,60) label:SetTextColor(Color(255,255,255)) and its still not working
label:Center()
Thx for the tip but it still is not centerd i think https://files.facepunch.com/forum/upload/309258/3e94e4d5-38a8-4a2a-b0d4-ef4c820ff355/Screenshot_31.png
Use label:SizeToContents() instead of SetSize
Works perf, thank yo uvery much!
Sorry, you need to Log In to post a reply to this thread.