Hallo PureBasic Gemeinde,
ich bin noch sehr neu in PureBasic, habe früher viel in Basic gemacht (unter DOS). Mein Ziel ist es Programme die eine Hardware steuern sollen mit einer guten Oberfläche unter Windows zu versehen. Aber das ist noch Zukunftsmusik!!!
Um in die Sprache (vorallem die Gadget-Befehle) hinein zu finden, habe ich mir einen kleinen Taschenrechner mit Visual Disigner erstellt und bin dabei ihn mit "Leben zu füllen".
Dabei ist mir auf gefallen, dass man die Schriftgrösse der Buttons ändern kann, wählt man aber eine andere Farbe, z.B. rot so wird dies schon im Visual Disigner ignoriert. Ich kann mich auf den Kopf stellen, aber es kommt immer nur schwarze Schrift heraus. Deshalb nun die Frage:
Wie kann ich die Schrift- und Hintergrund farbe eines Buttons einstellen?
Ich danke allen die mithelfen ganz recht herzlich!!!!!!
GRUSS
INGO
Schriftfarbe im Button
- Green Snake
- Beiträge: 1394
- Registriert: 22.02.2005 19:08
Visual Disigner
hallo
wie benutzt man eigentlich den viasual disigner?
kann mir da jemand ein beispiel machen?
greensnake
wie benutzt man eigentlich den viasual disigner?
kann mir da jemand ein beispiel machen?
greensnake
-.-"
www.purearea.net <-- DIE PB Site.
Hier was ausm CodeArchiv:
Hier was ausm CodeArchiv:
Code: Alles auswählen
; English forum:
; Author: Fweil
; Date: 11. November 2002
; Updated for PB3.70+ 09 June 2003 by Andre Beer
;
; F.Weil - 20021111
;
; This program shows how to interact for selecting colors and fonts and display colored and labeled two states buttons.
; Use the background and foreground colors selection buttons to define the right side two states button colors
; and the two states button itself to select a font by giving its attributes when selecting it or by checking
; appropriate checkboxes.
;
; The final touch was possible to support embeded characters thanks to Danilo's sample code for managing
; fonts with attributes. I did not implement strikeout attribute.
;
; This part of a larger program is free of use for PureBasic community.
;
; Gadgets numbers defined using constants for readability
;
#Gadget_Color1 = 105
#Gadget_Color2 = 106
#Gadget_Bold = 111
#Gadget_Italic = 112
#Gadget_CellHeight = 122
#Gadget_CellWidth = 123
#Gadget_TextColor1 = 131
#Gadget_TextColor2 = 132
#Gadget_2StateButton1 = 133
#Gadget_2StateButton2 = 134
#FONT_NORMAL = %00000000
#FONT_BOLD = %00000001
#FONT_ITALIC = %00000010
#FONT_UNDERLINE = %00000100
#FONT_STRIKEOUT = %00001000
#TRUE=1:#FALSE=0
;
; onMouseOver2StateButton is a signal set to #TRUE when the mouse passes over the 2 states button
;
onMouseOver2StateButton.l
Global onMouseOver2StateButton
Procedure.l IMin(a.l, b.l)
If a < b
ProcedureReturn a
Else
ProcedureReturn b
EndIf
EndProcedure
Procedure.l IMax(a.l, b.l)
If a > b
ProcedureReturn a
Else
ProcedureReturn b
EndIf
EndProcedure
;
; RGB2DecList returns the R, G, B list corresponding to Color in a string
;
Procedure.s RGB2DecList(Color.l)
ProcedureReturn Str(Red(Color)) + "," + Str(Green(Color)) + "," + Str(Blue(Color))
EndProcedure
;
; The callback just manages the onMouseOver feature for the 2 states button
;
Procedure MyWindowCallback(WindowID.l, Message.l, wParam.l, lParam.l)
Result.l = #PB_ProcessPureBasicEvents
If Message = #WM_SETCURSOR And wParam = GadgetID(#Gadget_2StateButton1)
HideGadget(#Gadget_2StateButton1, 1)
HideGadget(#Gadget_2StateButton2, 0)
onMouseOver2StateButton = #TRUE
EndIf
If onMouseOver2StateButton And Message = #WM_NCHITTEST And wParam = 0
onMouseOver2StateButton = #FALSE
HideGadget(#Gadget_2StateButton1, 0)
HideGadget(#Gadget_2StateButton2, 1)
EndIf
ProcedureReturn Result
EndProcedure
;
; MyColorRequester is there to return unchanged color when leaving the ColorRequester without
; selecting a new color
;
Procedure.l MyColorRequester(Color.l)
Result.l = ColorRequester()
If Result = -1
ProcedureReturn Color
Else
ProcedureReturn Result
EndIf
EndProcedure
Procedure CreateFont(Name$,Size,Style)
If (Style & #FONT_BOLD)
bold = 700
EndIf
If (Style & #FONT_ITALIC)
italic = 1
EndIf
If (Style & #FONT_UNDERLINE)
underline = 1
EndIf
If (Style & #FONT_STRIKEOUT)
strikeout = 1
EndIf
ProcedureReturn CreateFont_(Size,0,0,0,bold,italic,underline,strikeout,0,0,0,0,0,Name$)
EndProcedure
Procedure.l MyLabeledImage(ImageNumber.l, Width.l, Height.l, Color.l, TColor.l, Label.s, Font.s, Bold.l, Italic.l, FontSize.l)
Attributes = #FONT_NORMAL
If Bold
Attributes = Attributes | #FONT_BOLD
EndIf
If Italic
Attributes = Attributes | #FONT_ITALIC
EndIf
Normal = CreateFont(Font, FontSize, #FONT_NORMAL)
Bold = CreateFont(Font, FontSize, #FONT_BOLD)
Italic = CreateFont(Font, FontSize, #FONT_ITALIC)
Bold_Italic = CreateFont(Font, FontSize, #FONT_BOLD | #FONT_ITALIC)
Select Attributes
Case #FONT_NORMAL
FontToUse = Normal
Case #FONT_BOLD
FontToUse = Bold
Case #FONT_ITALIC
FontToUse = Italic
Case #FONT_BOLD | #FONT_ITALIC
FontToUse = Bold_Italic
Default
EndSelect
ImageID.l = CreateImage(ImageNumber, Width, Height)
StartDrawing(ImageOutput())
Box(0, 0, Width, Height, Color)
FrontColor(Red(TColor), Green(TColor), Blue(TColor))
DrawingFont(FontToUse)
DrawingMode(1)
If TextLength(Label) < Width
XPos.l = (Width - TextLength(Label)) / 2
Else
XPos.l = 4
EndIf
If TextLength("M") < Height
YPos.l = (Height - TextLength("M")) / 2 - 2
Else
YPos.l = 0
EndIf
Locate(XPos, YPos)
DrawText(Label)
StopDrawing()
ProcedureReturn ImageID
EndProcedure
;
; Refresh2StateButton changes the two buttons with modified colors and label
;
Procedure Refresh2StateButton(CellWidth.l, CellHeight.l, Color1.l, TextColor1.l, Color2.l, TextColor2.l, CellFont.s, CellFontSize, CellFontBold.l, CellFontItalic.l)
Bold.s = ""
Italic.s = ""
If CellFontBold
Bold.s = " Bold"
EndIf
If CellFontItalic
Italic.s = " Italic"
EndIf
MaxWidth.l = 110
MaxHeight.l = 35
FreeGadget(#Gadget_2StateButton1)
If MaxWidth - IMin(CellHeight, MaxHeight) / 2 > 0
ButtonImageGadget(#Gadget_2StateButton1, 480 - IMin(CellWidth, MaxWidth) / 2, MaxWidth - IMin(CellHeight, MaxHeight) / 2, IMin(CellWidth, MaxWidth), IMin(CellHeight, MaxHeight), MyLabeledImage(5, IMin(CellWidth, MaxWidth), IMin(CellHeight, MaxHeight), Color1, TextColor1, "Text font", CellFont, CellFontBold, CellFontItalic, CellFontSize))
EndIf
GadgetToolTip(#Gadget_2StateButton1, "Click here to change text font (actually " + CellFont + Bold + Italic + " " + Str(CellFontSize) + ")")
FreeGadget(#Gadget_2StateButton2)
ButtonImageGadget(#Gadget_2StateButton2, 480 - IMin(CellWidth, MaxWidth) / 2, MaxWidth - IMin(CellHeight, MaxHeight) / 2, IMin(CellWidth, MaxWidth), IMin(CellHeight, MaxHeight), MyLabeledImage(6, IMin(CellWidth, MaxWidth), IMin(CellHeight, MaxHeight), Color2, TextColor2, "Text font", CellFont, CellFontBold, CellFontItalic, CellFontSize))
GadgetToolTip(#Gadget_2StateButton2, "Click here to change text font (actually " + CellFont + Bold + Italic + " " + Str(CellFontSize) + ")")
HideGadget(#Gadget_2StateButton2, 1)
EndProcedure
;
; Main starts here
;
Quit.l = #FALSE
WindowXSize.l = 640
WindowYSize.l = 280
Color1.l = $804000
Color2.l = $007D7D
TextColor1.l = $80FFFF
TextColor2.l = $FF0000
CellHeight.l = 30
Centered.l = #TRUE
CellWidth.l = 160
CellFont.s = "Verdana"
CellFontSize.l = 12
hWnd.l = OpenWindow(0, 200, 200, WindowXSize, WindowYSize, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar, "F.Weil - Font selection and decorated buttons")
If hWnd
AddKeyboardShortcut(0, #PB_Shortcut_Escape, 99)
LoadFont(0, "Verdana", 8)
If CreateGadgetList(WindowID())
SetGadgetFont(#PB_Default,FontID())
CheckBoxGadget(#Gadget_Bold, 430, 160, 50, 20, "Bold")
GadgetToolTip(#Gadget_Bold, "Check this to use bold labels")
CheckBoxGadget(#Gadget_Italic, 510, 160, 50, 20, "Italic")
GadgetToolTip(#Gadget_Italic, "Check this to use italic labels")
Frame3DGadget(#Gadget_CellHeight + 100, 340, 10, 100, 60, "CellHeight", 0)
StringGadget(#Gadget_CellHeight, 360, 30, 60, 20, Str(CellHeight))
GadgetToolTip(#Gadget_CellHeight, "Enter subcells minimum height")
Frame3DGadget(#Gadget_CellWidth + 100, 450, 10, 100, 60, "CellWidth", 0)
StringGadget(#Gadget_CellWidth, 470, 30, 60, 20, Str(CellWidth))
GadgetToolTip(#Gadget_CellWidth, "Enter cells width")
Frame3DGadget(#Gadget_Color1 + 100, 100, 80, 80, 60, "BG1", 0)
ButtonImageGadget(#Gadget_Color1, 120, 100, 40, 20, MyLabeledImage(1, 40, 20, Color1, 0, "", "", 0, 0, 0))
GadgetToolTip(#Gadget_Color1, "Click here to change first background color (actually" + RGB2DecList(Color1) + ")")
Frame3DGadget(#Gadget_Color2 + 100, 180, 80, 80, 60, "BG2", 0)
ButtonImageGadget(#Gadget_Color2, 200, 100, 40, 20, MyLabeledImage(2, 40, 20, Color2, 0, "", "", 0, 0, 0))
GadgetToolTip(#Gadget_Color2, "Click here to change second background color (actually" + RGB2DecList(Color2) + ")")
Frame3DGadget(#Gadget_TextColor1 + 100, 260, 80, 80, 60, "TC1", 0)
ButtonImageGadget(#Gadget_TextColor1, 280, 100, 40, 20, MyLabeledImage(3, 40, 20, TextColor1, 0, "", "", 0, 0, 0))
GadgetToolTip(#Gadget_TextColor1, "Click here to change first text color (actually" + RGB2DecList(TextColor1) + ")")
Frame3DGadget(#Gadget_TextColor2 + 100, 340, 80, 80, 60, "TC2", 0)
ButtonImageGadget(#Gadget_TextColor2, 360, 100, 40, 20, MyLabeledImage(4, 40, 20, TextColor2, 0, "", "", 0, 0, 0))
GadgetToolTip(#Gadget_TextColor2, "Click here to change second text color (actually" + RGB2DecList(TextColor2) + ")")
Frame3DGadget(#Gadget_2StateButton1 + 100, 420, 80, 120, 60, "Font", 0)
ButtonImageGadget(#Gadget_2StateButton1, 430, 95, 100, 30, MyLabeledImage(5, 100, 30, Color1, TextColor1, "Text font", CellFont, CellFontBold, CellFontItalic, CellFontSize))
GadgetToolTip(#Gadget_2StateButton1, "Click here to change text font (actually " + CellFont + " " + Str(CellFontSize) + ")")
Frame3DGadget(#Gadget_2StateButton2 + 100, 420, 80, 120, 60, "Font", 0)
ButtonImageGadget(#Gadget_2StateButton2, 430, 95, 100, 30, MyLabeledImage(6, 100, 30, Color2, TextColor2, "Text font", CellFont, CellFontBold, CellFontItalic, CellFontSize))
GadgetToolTip(#Gadget_2StateButton2, "Click here to change text font (actually " + CellFont + " " + Str(CellFontSize) + ")")
HideGadget(#Gadget_2StateButton2, 1)
EndIf
SetWindowCallback(@MyWindowCallback())
Repeat
Select WaitWindowEvent()
Case #PB_EventCloseWindow
Quit = #TRUE
Case #PB_EventMenu
Select EventMenuID()
Case 99
Quit = #TRUE
EndSelect
Case #PB_EventGadget
Select EventGadgetID()
Case #Gadget_Color1 ; First background color
FreeGadget(#Gadget_Color1)
Color1 = MyColorRequester(Color1)
ButtonImageGadget(#Gadget_Color1, 120, 100, 40, 20, MyLabeledImage(1, 40, 20, Color1, 0, "", "", 0, 0, 0))
GadgetToolTip(#Gadget_Color1, "Click here to change first background color (actually" + RGB2DecList(Color1) + ")")
Case #Gadget_Color2 ; Second background color
FreeGadget(#Gadget_Color2)
Color2 = MyColorRequester(Color2)
ButtonImageGadget(#Gadget_Color2, 200, 100, 40, 20, MyLabeledImage(2, 40, 20, Color2, 0, "", "", 0, 0, 0))
GadgetToolTip(#Gadget_Color2, "Click here to change second background color (actually" + RGB2DecList(Color2) + ")")
Case #Gadget_Bold ; Bold CheckBox
CellFontBold = GetGadgetState(#Gadget_Bold)
Case #Gadget_Italic ; Italic CheckBox
CellFontItalic = GetGadgetState(#Gadget_Italic)
Case #Gadget_CellHeight ; CellHeight StringGadget
CellHeight = IMax(Val(GetGadgetText(#Gadget_CellHeight)), 1)
Case #Gadget_CellWidth ; CellWidth StringGadget
CellWidth = IMax(Val(GetGadgetText(#Gadget_CellWidth)), 1)
Case #Gadget_TextColor1 ; First Text Color
FreeGadget(#Gadget_TextColor1)
TextColor1 = MyColorRequester(TextColor1)
ButtonImageGadget(#Gadget_TextColor1, 280, 100, 40, 20, MyLabeledImage(3, 40, 20, TextColor1, 0, "", "", 0, 0, 0))
GadgetToolTip(#Gadget_TextColor1, "Click here to change first text color (actually" + RGB2DecList(TextColor1) + ")")
Case #Gadget_TextColor2 ; Second Text Color
FreeGadget(#Gadget_TextColor2)
TextColor2 = MyColorRequester(TextColor2)
ButtonImageGadget(#Gadget_TextColor2, 360, 100, 40, 20, MyLabeledImage(4, 40, 20, TextColor2, 0, "", "", 0, 0, 0))
GadgetToolTip(#Gadget_TextColor2, "Click here to change first text color (actually" + RGB2DecList(TextColor2) + ")")
Case #Gadget_2StateButton2 ; Font selector
Result = FontRequester(CellFont, CellFontSize, 0)
If SelectedFontStyle() & #PB_Font_Bold
CellFontBold = #TRUE
CellFont = CellFont + " Bold"
SetGadgetState(#Gadget_Bold, CellFontBold)
Else
CellFontBold = #FALSE
SetGadgetState(#Gadget_Bold, CellFontBold)
EndIf
If SelectedFontStyle() & #PB_Font_Italic
CellFontItalic = #TRUE
CellFont = CellFont + " Italic"
SetGadgetState(#Gadget_Italic, CellFontItalic)
Else
CellFontItalic = #FALSE
SetGadgetState(#Gadget_Italic, CellFontItalic)
EndIf
CellFont = SelectedFontName()
CellFontSize = SelectedFontSize()
EndSelect
Refresh2StateButton(CellWidth, CellHeight, Color1, TextColor1, Color2, TextColor2, CellFont, CellFontSize, CellFontBold, CellFontItalic)
EndSelect
Until Quit
EndIf
End
; ExecutableFormat=Windows
; CursorPosition=2
; FirstLine=1
; EnableXP
; EOF


und schon habt ihr den ingo verscheucht..
1.
der VisualDesigner zeigt zwar eine Farbauswahl an
aber einstellen lässt sich damit effektiv nichts (leider).
2.
Malen ist angesagt. Du kannst auf die Gadgets recht simpel was draufmalen wenn Du die E2D-Lib benutzt.
3.
siehe auch in der Hilfe unter Font
4.
ein kleines Beispiel
1.
der VisualDesigner zeigt zwar eine Farbauswahl an
aber einstellen lässt sich damit effektiv nichts (leider).
2.
Malen ist angesagt. Du kannst auf die Gadgets recht simpel was draufmalen wenn Du die E2D-Lib benutzt.
3.
siehe auch in der Hilfe unter Font
4.
ein kleines Beispiel
Code: Alles auswählen
;ff benutzt funktionen aus der E2D-Lib
; PureBasic Visual Designer v3.90 build 1361
;- Window Constants
;
Enumeration
#Window_0
EndEnumeration
;- Gadget Constants
;
Enumeration
#Button_0
#Button_1
#String_0
#Font_0
EndEnumeration
;- Fonts
;
Global FontID1
FontID1 = LoadFont(#Font_0, "MS Sans Serif", 10,#PB_Font_HighQuality)
If OpenWindow(#Window_0, 216, 0, 600, 300, #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar , "New window ( 0 )")
If CreateGadgetList(WindowID())
ButtonGadget(#Button_0, 80, 140, 180, 40, "")
ButtonGadget(#Button_1, 80, 200, 180, 30, "")
StringGadget(#String_0, 280, 200, 210, 20, "ändere mich mal")
SetGadgetFont(#String_0, FontID1)
EndIf
EndIf
Repeat
Event = WaitWindowEvent()
If Event = #PB_EventGadget
GadgetID = EventGadgetID()
If GadgetID = #Button_0
Debug "GadgetID: #Button_0"
ElseIf GadgetID = #Button_1
Debug "GadgetID: #Button_1"
ElseIf GadgetID = #String_0
Debug "GadgetID: #String_0"
If StartDrawing(GadgetOutput(#String_0))
DrawingFont(FontID())
FrontColor(255,0,0)
Locate (3,2)
DrawText(GetGadgetText(#String_0))
EndIf
StopDrawing()
EndIf
EndIf
Until Event = #PB_EventCloseWindow
End
pb aktuel 6.2 windoof aktuell und sowas von 10
Ich hab Tinnitus im Auge. Ich seh nur Pfeifen.
Ich hab Tinnitus im Auge. Ich seh nur Pfeifen.