bonjour tout le monde
est il possible de modifier le caption des boutons d'une boite de message
MessagDlg ??
merci d'avance
bonjour tout le monde
est il possible de modifier le caption des boutons d'une boite de message
MessagDlg ??
merci d'avance
Oui
Dans le vocabulaire des couturiers seulement, patron est synonyme de modèle.
Aymond d'Alost
salut
regarde avec
SendMessage et WM_SETTEXT
@+ Phil
Blaise PascalNous souhaitons la vérité et nous trouvons qu'incertitude. [...]
Nous sommes incapables de ne pas souhaiter la vérité et le bonheur, et sommes incapables ni de certitude ni de bonheur.
PS : n'oubliez pas le tag
Bonjour à toutes et à tous,
@ Sky88, Une petite idée :
Utilisation :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 function MonMessageDialog(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; Captions: array of string): Integer; var aMsgDlg: TForm; i: Integer; dlgButton: TButton; CaptionIndex: Integer; begin { Crée la boite Dialogue } aMsgDlg := CreateMessageDialog(Msg, DlgType, Buttons); captionIndex := 0; for i := 0 to aMsgDlg.ComponentCount - 1 do begin if (aMsgDlg.Components[i] is TButton) then begin dlgButton := TButton(aMsgDlg.Components[i]); if CaptionIndex > High(Captions) then Break; dlgButton.Caption := Captions[CaptionIndex]; Inc(CaptionIndex); end; end; Result := aMsgDlg.ShowModal; end;
@+,
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 procedure TForm1.Button1Click(Sender: TObject); begin if MonMessageDialog('Bonjour...?', mtConfirmation, mbOKCancel, ['La terre', 'Le ciel']) = mrOk then ShowMessage('"La terre" cliqué') else ShowMessage('"Le ciel" cliqué'); end;
Cincap
mais ça ne marche pas si je crée une boite de dialogue avec un seul bouton comme les boites mtwarning???
et comment editer aussi le caption de la boite de dialogue??
merci à vous je l'ai fait
@ Sky88, on peut savoir comment !
Cela pourra servir à tous.
@+,
cincap
Pour le changement de Titre, ça serait tout simplement :
Il faut rappeler que MessageDlg est une fonction dont on a le source, il suffit de recopier MessageDlg, MessageDlgPos, MessageDlgPosHelp et donc faire ceci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 aMsgDlg := CreateMessageDialog(Msg, DlgType, Buttons); aMsgDlg.Caption := ATitle; // nouveau paramètre
ou encore cela
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129 {* ----------------------------------------------------------------------------- MessageDlgCustomBtn fonctionne comme MessageDlg avec les libellés des boutons libres @param Msg Chaine à Afficher @param DlgType Type du Dialogue @param Buttons Ensemble de boutons @param ButtonStrings Chaine spécifique pour chaque Bouton, Mettre dans ButtonsStrings les chaines consécutivement dans l'ordre de l'énumération, pas dans l'ordre du Set ! @param HelpCtx Contexte d'Aide @return Entier Résultat associé à chaque Bouton ------------------------------------------------------------------------------ } function MessageDlgCustomBtn(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; const ButtonStrings: array of String; HelpCtx: Longint = 0): Integer; begin Result := MessageDlgPosHelpCustomBtn(Msg, DlgType, Buttons, ButtonStrings, HelpCtx, -1, -1, ''); end; {* --- MessageDlgCustomBtn ----------------------------------------------------} function MessageDlgPosCustomBtn(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; const ButtonStrings: array of String; HelpCtx: Longint; X, Y: Integer): Integer; begin Result := MessageDlgPosHelpCustomBtn(Msg, DlgType, Buttons, ButtonStrings, HelpCtx, X, Y, ''); end; {* --- MessageDlgCustomBtn ----------------------------------------------------} function MessageDlgPosHelpCustomBtn(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; const ButtonStrings: array of String; HelpCtx: Longint; X, Y: Integer; const HelpFileName: string): Integer; const ModalResults: array[TMsgDlgBtn] of Integer = (mrYes, mrNo, mrOk, mrCancel, mrAbort, mrRetry, mrIgnore, mrAll, mrNoToAll, mrYesToAll, 0); var MsgForm: TForm; IndexControls: Integer; IndexButtons: TMsgDlgBtn; IndexStrings: Integer; NewWidth, AllWidth, BaseWidth, BaseHeigth, BaseLeft, BaseTop: Integer; TextRect: TRect; begin MsgForm := CreateMessageDialog(Msg, DlgType, Buttons); with MsgForm do try try if Length(ButtonStrings) > 0 then begin IndexStrings := Low(ButtonStrings); for IndexButtons := Low(IndexButtons) to High(IndexButtons) do begin if IndexButtons in Buttons then begin for IndexControls := 0 to ControlCount - 1 do begin if Controls[IndexControls] is TButton then begin with TButton(Controls[IndexControls]) do begin if ModalResults[IndexButtons] = ModalResult then begin Caption := ButtonStrings[IndexStrings]; Inc(IndexStrings); if IndexStrings > High(ButtonStrings) then SysUtils.Abort; end; end; end; end; end; end; end; finally AllWidth := 0; BaseHeigth := 0; BaseTop := MaxInt; for IndexControls := 0 to ControlCount - 1 do begin if Controls[IndexControls] is TButton then begin with TButton(Controls[IndexControls]) do begin TextRect := Rect(0,0,0,0); Windows.DrawText(Canvas.Handle, PChar(Caption), -1, TextRect, DT_CALCRECT or DT_LEFT or DT_SINGLELINE or DrawTextBiDiModeFlagsReadingOnly); with TextRect do NewWidth := Right - Left + 16; if NewWidth > Width then Width := NewWidth; Inc(AllWidth, Width + 8); if Height > BaseHeigth then BaseHeigth := Height; if Top < BaseTop then BaseTop := Top; end; end; end; if AllWidth + 16 > ClientWidth then BaseWidth := ClientWidth - 16 else BaseWidth := AllWidth; BaseLeft := (MsgForm.ClientWidth - BaseWidth) div 2; for IndexControls := 0 to ControlCount - 1 do begin if Controls[IndexControls] is TButton then begin with TButton(Controls[IndexControls]) do begin if (BaseWidth <> AllWidth) and (BaseLeft + Width > MsgForm.ClientWidth) then begin BaseLeft := (MsgForm.ClientWidth - BaseWidth) div 2; Inc(BaseTop, BaseHeigth + 8); end; Left := BaseLeft; Top := BaseTop; Inc(BaseLeft, Width + 8); end; end; end; HelpContext := HelpCtx; HelpFile := HelpFileName; if X >= 0 then Left := X; if Y >= 0 then Top := Y; if (Y < 0) and (X < 0) then Position := poScreenCenter; Result := ShowModal; end; finally Free; end; end;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178 {* ----------------------------------------------------------------------------- MessageDlgFont fonctionne comme MessageDlg avec la Gestion de la Font pour la fenêtre et les Boutons @param Msg Chaine à Afficher @param DlgType Type du Dialogue @param Buttons Ensemble de boutons @param DefaultButton Désigne le bouton qui sera actif par défaut @param FontMsg Font spécifique pour Fenêtre et Boutons @param HelpCtx Contexte d'Aide @return Entier Résultat associé à chaque Bouton ------------------------------------------------------------------------------ } function MessageDlgFont(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; FontMsg: TFont; HelpCtx: Longint = 0): Integer; begin Result := MessageDlgPosHelpFont(Msg, DlgType, Buttons, FontMsg, HelpCtx, -1, -1, ''); end; {* --- MessageDlgFont ---------------------------------------------------------} function MessageDlgFont(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; DefaultButton: TMsgDlgBtn; FontMsg: TFont; HelpCtx: Longint = 0): Integer; begin Result := MessageDlgPosHelpFont(Msg, DlgType, Buttons, DefaultButton, FontMsg, HelpCtx, -1, -1, ''); end; {* --- MessageDlgFont ---------------------------------------------------------} function MessageDlgPosFont(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; FontMsg: TFont; HelpCtx: Longint; X, Y: Integer): Integer; begin Result := MessageDlgPosHelpFont(Msg, DlgType, Buttons, FontMsg, HelpCtx, X, Y, ''); end; {* --- MessageDlgFont ---------------------------------------------------------} function MessageDlgPosFont(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; DefaultButton: TMsgDlgBtn; FontMsg: TFont; HelpCtx: Longint; X, Y: Integer): Integer; begin Result := MessageDlgPosHelpFont(Msg, DlgType, Buttons, DefaultButton, FontMsg, HelpCtx, X, Y, ''); end; {* --- MessageDlgFont forward -------------------------------------------------} function _MessageDlgPosHelpFont(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; const DefaultButtonArray: array of TMsgDlgBtn; FontMsg: TFont; HelpCtx: Longint; X, Y: Integer; const HelpFileName: string): Integer; forward; {* --- MessageDlgFont ---------------------------------------------------------} function MessageDlgPosHelpFont(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; FontMsg: TFont; HelpCtx: Longint; X, Y: Integer; const HelpFileName: string): Integer; var DefaultButtonArray: array of TMsgDlgBtn; begin SetLength(DefaultButtonArray, 0); Result := _MessageDlgPosHelpFont(Msg, DlgType, Buttons, [], FontMsg, HelpCtx, X, Y, ''); end; {* --- MessageDlgFont ---------------------------------------------------------} function MessageDlgPosHelpFont(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; DefaultButton: TMsgDlgBtn; FontMsg: TFont; HelpCtx: Longint; X, Y: Integer; const HelpFileName: string): Integer; var DefaultButtonArray: array of TMsgDlgBtn; begin SetLength(DefaultButtonArray, 1); DefaultButtonArray[0] := DefaultButton; Result := _MessageDlgPosHelpFont(Msg, DlgType, Buttons, DefaultButtonArray, FontMsg, HelpCtx, X, Y, ''); end; {* --- MessageDlgFont ---------------------------------------------------------} function _MessageDlgPosHelpFont(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; const DefaultButtonArray: array of TMsgDlgBtn; FontMsg: TFont; HelpCtx: Longint; X, Y: Integer; const HelpFileName: string): Integer; var MsgForm: TForm; MsgLabel: TComponent; IndexControls: Integer; OldWidth, OldFontSize, OldLabelWidth, OldLabelHeight, Decalage: Integer; OldButton: TButton; OverButton: TBitBtn; procedure SetOverButtonKind(AKind: TBitBtnKind; BtnType: TMsgDlgBtn); begin OverButton.Kind := AKind; OverButton.ModalResult := OldButton.ModalResult; if OldButton.Default then begin OldButton.Default := False; OverButton.Default := (Length(DefaultButtonArray) = 0) or ((Length(DefaultButtonArray) = 1) and (DefaultButtonArray[0] = BtnType)); end else OverButton.Default := (Length(DefaultButtonArray) = 1) and (DefaultButtonArray[0] = BtnType); if OverButton.Default then OverButton.TabOrder := 0; // Seul moyen de contourner le Default déjà posé par CreateMessageDialog, Astuce de JTS ! if OldButton.Cancel then begin OldButton.Cancel := False; OverButton.Cancel := True; end; if Assigned(OldButton.OnClick) then OverButton.OnClick := OldButton.OnClick; end; begin MsgForm := CreateMessageDialog(Msg, DlgType, Buttons); with MsgForm do try MsgLabel := FindComponent('Message'); if MsgLabel is TLabel then begin OldLabelWidth := TLabel(MsgLabel).Width; OldLabelHeight := TLabel(MsgLabel).Height; OldFontSize := Math.Max(TLabel(MsgLabel).Font.Size, 1); TLabel(MsgLabel).Font.Assign(FontMsg); TLabel(MsgLabel).Width := Math.Min(Math.Max(OldLabelWidth, Round(OldLabelWidth * TLabel(MsgLabel).Font.Size / OldFontSize)), Screen.Width div 2); OldWidth := Width; Width := Math.Max(Width, Width - OldLabelWidth + TLabel(MsgLabel).Width); Decalage := (Width - OldWidth) div 2; for IndexControls := 0 to ControlCount - 1 do begin if Controls[IndexControls] is TButton then begin OldButton := TButton(Controls[IndexControls]); // utilisé dans SetOverButtonKind OverButton := TBitBtn.Create(MsgForm); OverButton.Left := OldButton.Left + Decalage; OverButton.Top := OldButton.Top; OverButton.Height := OldButton.Height + 2; OverButton.Width := OldButton.Width; OverButton.Parent := OldButton.Parent; OverButton.Anchors := OldButton.Anchors - [akTop] + [akBottom]; case OldButton.ModalResult of mrNone: SetOverButtonKind(bkHelp, mbHelp); mrOk: SetOverButtonKind(bkOK, mbOK); mrCancel: SetOverButtonKind(bkCancel, mbCancel); mrAbort: SetOverButtonKind(bkAbort, mbAbort); mrRetry: SetOverButtonKind(bkRetry, mbRetry); mrIgnore: SetOverButtonKind(bkIgnore, mbIgnore); mrYes: SetOverButtonKind(bkYes, mbYes); mrNo: SetOverButtonKind(bkNo, mbNo); mrAll: SetOverButtonKind(bkAll, mbAll); mrNoToAll: SetOverButtonKind(bkNo, mbYesToAll); mrYesToAll: SetOverButtonKind(bkYes, mbNoToAll); end; OldButton.Enabled := False; OldButton.Visible := False; end; end; Height := Math.Max(Height, Height - OldLabelHeight + TLabel(MsgLabel).Height); Left := (Screen.Width div 2) - (Width div 2); Top := (Screen.Height div 2) - (Height div 2); end; HelpContext := HelpCtx; HelpFile := HelpFileName; if X >= 0 then Left := X; if Y >= 0 then Top := Y; if (Y < 0) and (X < 0) then Position := poScreenCenter; Result := ShowModal(); finally Free; end; end;
Aide via F1 - FAQ - Guide du développeur Delphi devant un problème - Pensez-y !
Attention Troll Méchant !
"Quand un homme a faim, mieux vaut lui apprendre à pêcher que de lui donner un poisson" Confucius
Mieux vaut se taire et paraître idiot, Que l'ouvrir et de le confirmer !
L'ignorance n'excuse pas la médiocrité !
L'expérience, c'est le nom que chacun donne à ses erreurs. (Oscar Wilde)
Il faut avoir le courage de se tromper et d'apprendre de ses erreurs
@ ShaiLeTroll, merci pour le complément de l'info, j'en conclut que ma fonction proposée est dépassée !
@+,
Cincap
Tu es un peu dur avec toi, non c'est surtout que l'on a un problème avec des libellés de bouton plus long que la taille par défaut d'un bouton d'un MessageDlg, il faut donc les agrandir et donc les déplacer les un par rapport aux autres, ta fonction est un bon point de départ pour ensuite la faire évoluer pour gérer les effets de bord ... ma fonction est encore largement buggée, ...
Aide via F1 - FAQ - Guide du développeur Delphi devant un problème - Pensez-y !
Attention Troll Méchant !
"Quand un homme a faim, mieux vaut lui apprendre à pêcher que de lui donner un poisson" Confucius
Mieux vaut se taire et paraître idiot, Que l'ouvrir et de le confirmer !
L'ignorance n'excuse pas la médiocrité !
L'expérience, c'est le nom que chacun donne à ses erreurs. (Oscar Wilde)
Il faut avoir le courage de se tromper et d'apprendre de ses erreurs
j'atend vous remarque sur cet outils
Bonjour à toutes et à tous,
@ tarek_ep, Malheureusement payant et n'apporte rien à concevoir personnellement un message.
@+,
Cincap
Merci du lien Cincap^^
Cincap t'aurais pas une idée comment avoir un composant pouvant etre placé en avant plan (comme un Tpanel) mais pouvant aussi etre transparent ?
(pas une form^^)
Cliquez ici et reprenez le pouvoir !
A bas IE !, Google, et le pistage du net, testons DuckDuckGo.com
Lords Of The Realm II Download : Lords of the realm 2
Infos en anglais :Ici
@ Dragonno, la Vcl LMD a un composant panel qui gère la transparence.
Sinon tu crées ton composant perso.
@+,
Cincap
Merci Cincap
Pour la création de composant je suis en train d'essayer d'apprendre mais c'est le seul truc que je suis pas encore arrivé à comprendre jusqu'ici de mes cours Delphi :/
EDIT : Philnext m'a dit que Jedi VCL possède un composant transparent et je dois justement installer cette VCL, merci^^
Cliquez ici et reprenez le pouvoir !
A bas IE !, Google, et le pistage du net, testons DuckDuckGo.com
Lords Of The Realm II Download : Lords of the realm 2
Infos en anglais :Ici
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager