teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

Paintメソッドの中身を記載

2019/10/29 14:05

投稿

dem0nmichik0
dem0nmichik0

スコア37

title CHANGED
File without changes
body CHANGED
@@ -83,8 +83,200 @@
83
83
  RegisterComponents('Samples', [TDoor]);
84
84
  end;
85
85
 
86
+ // WM_PAINTメッセージで起動
87
+ // クライアントエリアに更新領域が存在するときにコール
88
+ procedure TDoor.Paint;
89
+ var
90
+ x1, y1: Integer;
91
+ x2, y2: Integer;
92
+ x_space, y_space: Integer;
93
+
94
+ begin
95
+ // 四角形の場合
96
+ if FShape = stRectangle then
97
+ begin
98
+ with Canvas do begin
99
+ // FSahpeColor色で塗りつぶし
100
+ Brush.Color:= FShapeColor;
101
+ Brush.Style:= bsSolid;
102
+ FillRect(Rect(Left, Top, (Left+Width), (Top+Height)));
103
+ // 黒色で太さ1で枠線描画
104
+ Pen.Color:= clBlack;
105
+ Pen.Style:= psSolid;
106
+ Pen.Width:= 1;
107
+ Rectangle(Rect(Left, Top, (Left+Width), (Top+Height)));
108
+
109
+ // 文字列の描画
110
+ TextOut(FWidth_C, FHeight_C, FCaption);
111
+ end;
112
+ end
113
+ // 円の場合
114
+ else if FShape = stCircle then
115
+ begin
116
+ with Canvas do begin
117
+ // Color色で塗りつぶし
118
+ Brush.Color:= Color;
119
+ Brush.Style:= bsSolid;
120
+ FillRect(Rect(Left, Top, (Left+Width), (Top+Height)));
121
+
122
+ if Width > Height then
123
+ begin
124
+ x_space:= Width - Height;
125
+ x1:= Left + (x_space div 2);
126
+ y1:= Top;
127
+ x2:= x1 + Height;
128
+ y2:= y1 + Height;
129
+ end
130
+ else
131
+ begin
132
+ y_space:= Height - Width;
133
+ x1:= Left;
134
+ y1:= Top + (y_space div 2);
135
+ x2:= x1 + Width;
136
+ y2:= y1 + Width;
137
+ end;
138
+
139
+ // FSahpeColor色で塗りつぶし
140
+ Brush.Color:= FShapeColor;
141
+ Brush.Style:= bsSolid;
142
+ // 黒色で太さ1で枠線描画
143
+ Pen.Color:= clBlack;
144
+ Pen.Style:= psSolid;
145
+ Pen.Width:= 1;
146
+ Ellipse(x1, y1, x2, y2);
147
+
148
+ // 文字列の描画
149
+ TextOut(FWidth_C, FHeight_C, FCaption);
150
+ end;
151
+ end
152
+ // 楕円の場合
153
+ else if FShape = stEllipse then
154
+ begin
155
+ with Canvas do begin
156
+ // Color色で塗りつぶし
157
+ Brush.Color:= Color;
158
+ Brush.Style:= bsSolid;
159
+ FillRect(Rect(Left, Top, (Left+Width), (Top+Height)));
160
+ // FSahpeColor色で塗りつぶし
161
+ Brush.Color:= FShapeColor;
162
+ Brush.Style:= bsSolid;
163
+ // 黒色で太さ1で枠線描画
164
+ Pen.Color:= clBlack;
165
+ Pen.Style:= psSolid;
166
+ Pen.Width:= 1;
167
+ Ellipse(Left, Top, (Left+Width), (Top+Height));
168
+
169
+ // 文字列の描画
170
+ TextOut(FWidth_C, FHeight_C, FCaption);
171
+ end;
172
+ end
173
+ // 角の丸い四角形の場合
174
+ else if FShape = stRoundRect then
175
+ begin
176
+ with Canvas do begin
177
+ // Color色で塗りつぶし
178
+ Brush.Color:= Color;
179
+ Brush.Style:= bsSolid;
180
+ FillRect(Rect(Left, Top, (Left+Width), (Top+Height)));
181
+ // FSahpeColor色で塗りつぶし
182
+ Brush.Color:= FShapeColor;
183
+ Brush.Style:= bsSolid;
184
+ // 黒色で太さ1で枠線描画
185
+ Pen.Color:= clBlack;
186
+ Pen.Style:= psSolid;
187
+ Pen.Width:= 1;
188
+ RoundRect(Left, Top, Width, Height, 10, 10);
189
+
190
+ // 文字列の描画
191
+ TextOut(FWidth_C, FHeight_C, FCaption);
192
+ end;
193
+ end
194
+ // 角の丸い正方形の場合
195
+ else if FShape = stRoundSquare then
196
+ begin
197
+ with Canvas do begin
198
+ if Width > Height then
199
+ begin
200
+ x_space:= Width - Height;
201
+ x1:= Left + (x_space div 2);
202
+ y1:= Top;
203
+ x2:= x1 + Height;
204
+ y2:= y1 + Height;
205
+ end
206
+ else
207
+ begin
208
+ y_space:= Height - Width;
209
+ x1:= Left;
210
+ y1:= Top + (y_space div 2);
211
+ x2:= x1 + Width;
212
+ y2:= y1 + Width;
213
+ end;
214
+
215
+ // Color色で塗りつぶし
216
+ Brush.Color:= Color;
217
+ Brush.Style:= bsSolid;
218
+ FillRect(Rect(Left, Top, (Left+Width), (Top+Height)));
219
+ // FSahpeColor色で塗りつぶし
220
+ Brush.Color:= FShapeColor;
221
+ Brush.Style:= bsSolid;
222
+ // 黒色で太さ1で枠線描画
223
+ Pen.Color:= clBlack;
224
+ Pen.Style:= psSolid;
225
+ Pen.Width:= 1;
226
+ RoundRect(x1, y1, x2, y2, 10, 10);
227
+
228
+ // 文字列の描画
229
+ TextOut(FWidth_C, FHeight_C, FCaption);
230
+ end;
231
+ end
232
+ // 正方形の場合
233
+ else if FShape = stSquare then
234
+ begin
235
+ with Canvas do begin
236
+ // Color色で塗りつぶし
237
+ Brush.Color:= Color;
238
+ Brush.Style:= bsSolid;
239
+ FillRect(Rect(Left, Top, (Left+Width), (Top+Height)));
240
+
241
+ if Width > Height then
242
+ begin
243
+ x_space:= Width - Height;
244
+ x1:= Left + (x_space div 2);
245
+ y1:= Top;
246
+ x2:= x1 + Height;
247
+ y2:= y1 + Height;
248
+ end
249
+ else
250
+ begin
251
+ y_space:= Height - Width;
252
+ x1:= Left;
253
+ y1:= Top + (y_space div 2);
254
+ x2:= x1 + Width;
255
+ y2:= y1 + Width;
256
+ end;
257
+
258
+ // FSahpeColor色で塗りつぶし
259
+ Brush.Color:= FShapeColor;
260
+ Brush.Style:= bsSolid;
261
+ // 黒色で太さ1で枠線描画
262
+ Pen.Color:= clBlack;
263
+ Pen.Style:= psSolid;
264
+ Pen.Width:= 1;
265
+ Rectangle(Rect(x1, y1, x2, y2));
266
+
267
+ // ためしにやってみたが,フォントサイズが変更しなかった.
268
+ Font.Assign(Font);
269
+ // 文字列の描画
270
+ TextOut(FWidth_C, FHeight_C, FCaption);
271
+ end;
272
+ end;
273
+
274
+ // FCaption.
275
+ // Font.Size
276
+ end;
277
+
278
+
86
279
  //Createメソッド省略
87
- //Paintメソッド省略
88
280
  //SetShapeメソッド省略
89
281
  //SetShapeColorメソッド省略
90
282
  //SetCaptionメソッド省略

2

ソースコードの記載

2019/10/29 14:05

投稿

dem0nmichik0
dem0nmichik0

スコア37

title CHANGED
File without changes
body CHANGED
@@ -10,8 +10,86 @@
10
10
  ![](74359643cf47064459801374af16dcbd.jpeg)
11
11
  図2 Sizeプロパティを16にした時の画面
12
12
 
13
- ソースコードを載せようとしましたが,文字数が10,000文字以上になり,載せられませんでした.申し訳ありません.
13
+ ###実現方法
14
- ([最新ではあせんが,前回質問した時ソースコードが記載ています](https://teratail.com/questions/199005))
14
+ 文字列のサイズを変更する方法ウィンドウメッセージのWM_SETFONTイベントを発生させる必要がるだろうと思っていす.ですが,WM_SETFONTイベント発生せ方が分からず困っています.どなたがご教授お願いいたします.
15
15
 
16
- ###実現方法
16
+ ###ソースコード
17
+ 文字数が10,000文字以上になるため,各種メソッド部分をわざと消しています.
18
+ ```Delphi
19
+ unit Door;
20
+ // Delphi
21
+ interface
22
+
23
+ uses
24
+ Winapi.Windows, Winapi.Messages, System.SysUtils, System.Classes,
25
+ Vcl.Controls, Vcl.Graphics, Vcl.Forms, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Dialogs;
26
+
27
+ type
28
+ TDoor = class(TCustomControl)
29
+ private
30
+ { Private 宣言 }
31
+ FCaption: UnicodeString;
32
+ FShape: TShapeType;
33
+ FShapeColor: TColor;
34
+ FWidth_C: Integer;
35
+ FHeight_C: Integer;
36
+
37
+ procedure SetShape(Value: TShapeType);
38
+ procedure SetShapeColor(Value: TColor);
39
+ procedure SetCaption(Value: UnicodeString);
40
+ procedure SetWidth_C(Value: Integer);
41
+ procedure SetHeight_C(Value: Integer);
42
+ protected
43
+ { Protected 宣言 }
44
+ public
45
+ { Public 宣言 }
46
+ left: Integer;
47
+ top: Integer;
48
+
49
+ // コンストラクタ(オーバーライド)
50
+ constructor Create( AOwner: TComponent ); override;
51
+ procedure Paint; override;
52
+ published
53
+ { Published 宣言 }
54
+ // プロパティにdefaultを付けるとデフォルト値にできる
55
+ property Shape: TShapeType read FShape write SetShape default stRectangle;
56
+ property ShapeColor: TColor read FShapeColor write SetShapeColor;
57
+ property Caption: UnicodeString read FCaption write SetCaption;
58
+ property Width_C: Integer read FWidth_C write SetWidth_C;
59
+ property Height_C: Integer read FHeight_C write SetHeight_C;
60
+ // 継承プロパティ(再宣言するとオブジェクトインスペクタに表示できるようになる)
61
+ property Anchors;
62
+ property Color;
63
+ property Enabled;
64
+ property Font;
65
+ property Name;
66
+ property ParentColor;
67
+ property Visible;
68
+ property OnClick;
69
+ property OnDblClick;
70
+ end;
71
+
72
+ procedure Register;
73
+
17
- 文字列のサイズを変更する方法はウィンドウメッセージのWM_SETFONTイベントを発生させる必要があるだろうと思っています.ですが,WM_SETFONTイベントの発生させ方が分からず困っています.どなたがご教授お願いいたします.
74
+ //---------------------------------------------------------------------------
75
+ implementation
76
+
77
+ const
78
+ DelphiWindows: array [1 .. 1] of PWideChar = ('TAppBuilder');
79
+
80
+ procedure Register;
81
+ begin
82
+ // 「Samples」パレットにドアを登録
83
+ RegisterComponents('Samples', [TDoor]);
84
+ end;
85
+
86
+ //Createメソッド省略
87
+ //Paintメソッド省略
88
+ //SetShapeメソッド省略
89
+ //SetShapeColorメソッド省略
90
+ //SetCaptionメソッド省略
91
+ //SetWidth_Cメソッド省略
92
+ //SetHeight_Cメソッド省略
93
+
94
+ end.
95
+ ```

1

実現方法の追加

2019/10/24 15:10

投稿

dem0nmichik0
dem0nmichik0

スコア37

title CHANGED
File without changes
body CHANGED
@@ -2,7 +2,7 @@
2
2
  四角形や円などの図形と文字列を同時に生成する自作コンポーネントを作成すること.
3
3
 
4
4
  ###困っていること
5
- CustomControlクラスを継承したクラスを作成し,CustomControlのプロパティであるFontを継承しました.ですが,テストアプリでFontのSizeプロパティを変更しても文字列のサイズが変更せずに困っています.どなたかご教授お願いいたします.
5
+ CustomControlクラスを継承したクラスを作成し,CustomControlのプロパティであるFontを継承しました.ですが,テストアプリでFontのSizeプロパティを変更しても文字列のサイズが変更せずに困っています.
6
6
 
7
7
  ![](d82c2e11f359d83ef79aa978329a5788.jpeg)
8
8
  図1 文字列のサイズが変わらないインスタンス
@@ -11,4 +11,7 @@
11
11
  図2 Sizeプロパティを16にした時の画面
12
12
 
13
13
  ソースコードを載せようとしましたが,文字数が10,000文字以上になり,載せられませんでした.申し訳ありません.
14
- ([最新ではありませんが,前回質問した時のソースコードが記載されています](https://teratail.com/questions/199005))
14
+ ([最新ではありませんが,前回質問した時のソースコードが記載されています](https://teratail.com/questions/199005))
15
+
16
+ ###実現方法
17
+ 文字列のサイズを変更する方法はウィンドウメッセージのWM_SETFONTイベントを発生させる必要があるだろうと思っています.ですが,WM_SETFONTイベントの発生させ方が分からず困っています.どなたがご教授お願いいたします.