OSDN Git Service

QuestPanelの最小行数を変更できるようにする
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / View / GrowLeftLabel.cs
1 // Copyright (C) 2019 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
2 //\r
3 // Licensed under the Apache License, Version 2.0 (the "License");\r
4 // you may not use this file except in compliance with the License.\r
5 // You may obtain a copy of the License at\r
6 //\r
7 //    http://www.apache.org/licenses/LICENSE-2.0\r
8 //\r
9 // Unless required by applicable law or agreed to in writing, software\r
10 // distributed under the License is distributed on an "AS IS" BASIS,\r
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12 // See the License for the specific language governing permissions and\r
13 // limitations under the License.\r
14 \r
15 using System;\r
16 using System.ComponentModel;\r
17 using System.Drawing;\r
18 using System.Windows.Forms;\r
19 \r
20 namespace KancolleSniffer.View\r
21 {\r
22     [DesignerCategory("Code")]\r
23     public class GrowLeftLabel : Label\r
24     {\r
25         private int _right = int.MinValue;\r
26         private int _left;\r
27         private bool _growLeft;\r
28 \r
29         public bool GrowLeft\r
30         {\r
31             get => _growLeft;\r
32             set\r
33             {\r
34                 _growLeft = value;\r
35                 AutoSize = true;\r
36                 Size = Size.Empty;\r
37             }\r
38         }\r
39 \r
40         public GrowLeftLabel()\r
41         {\r
42             UseMnemonic = false;\r
43         }\r
44 \r
45         protected override void OnSizeChanged(EventArgs args)\r
46         {\r
47             base.OnSizeChanged(args);\r
48             AdjustLocation();\r
49         }\r
50 \r
51         protected override void OnLayout(LayoutEventArgs args)\r
52         {\r
53             base.OnLayout(args);\r
54             AdjustLocation();\r
55         }\r
56 \r
57         private void AdjustLocation()\r
58         {\r
59             if (!GrowLeft)\r
60                 return;\r
61             if (_right == int.MinValue || _left != Left)\r
62             {\r
63                 _right = Right;\r
64                 _left = Left;\r
65                 return;\r
66             }\r
67             if (_right == Right)\r
68                 return;\r
69             _left -= Right - _right;\r
70             Location = new Point(_left, Top);\r
71         }\r
72     }\r
73 }