Skip to content

Commit b27946c

Browse files
committed
changed treeView.SelectedNodeChanged to AfterSelect;
some minor fixes in ScrollableControl;
1 parent 76b62b0 commit b27946c

File tree

9 files changed

+147
-61
lines changed

9 files changed

+147
-61
lines changed

Examples/ControlsExtensions.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,13 @@ public static T Create<T>(
107107
if (lastChild != null)
108108
{
109109
var lastChildY = lastChild.Location.Y;
110-
if (lastChildY >= topOffset)
111110
{
112111
if (placeToRight)
113112
{
114113
leftOffset = lastChild.Location.X + lastChild.Width + margin;
115114
topOffset = lastChildY;
116115
}
117-
else
116+
else if (lastChildY >= topOffset)
118117
topOffset = lastChildY + lineHeight;
119118
}
120119
}

Examples/FormExamples.cs

+12-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public FormExamples()
2525

2626
treeView = new TreeView();
2727
treeView.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom;
28-
treeView.BorderColor = uwfBorderColor;
2928
treeView.Location = new Point(0, uwfHeaderHeight - 1); // All controls should be placed with Form header offset.
3029
treeView.Height = Height - uwfHeaderHeight + 1;
3130
treeView.Width = 220;
@@ -36,7 +35,12 @@ public FormExamples()
3635
var labelNote = new Label();
3736
labelNote.Font = new Font("Arial", 14, FontStyle.Bold);
3837
labelNote.Location = new Point(treeView.Location.X + treeView.Width + 16, treeView.Location.Y);
39-
labelNote.Text = "This is not completed overview of UWF controls. \r\nWork in progress.";
38+
labelNote.Text =
39+
"This is not completed overview of UWF controls.\r\n" +
40+
"Work in progress.\r\n\r\n" +
41+
"Do not forget that you can still modify controls\r\n" +
42+
"with 'SWF Inspector' which is located in drop down\r\n" +
43+
"menu 'Window' -> 'UnityWinForms'.";
4044

4145
Controls.Add(labelNote);
4246

@@ -70,6 +74,9 @@ public FormExamples()
7074
var nodeNumericUpDown = new TreeNode("NumericUpDown");
7175
nodeNumericUpDown.Tag = typeof(PanelNumericUpDown);
7276

77+
var nodePanel = new TreeNode("Panel");
78+
nodePanel.Tag = typeof(PanelPanel);
79+
7380
var nodePictureBox = new TreeNode("PictureBox");
7481
nodePictureBox.Tag = typeof(PanelPictureBox);
7582

@@ -90,6 +97,7 @@ public FormExamples()
9097
nodeControls.Nodes.Add(nodeMenuStrip);
9198
nodeControls.Nodes.Add(nodeMonthCalendar);
9299
nodeControls.Nodes.Add(nodeNumericUpDown);
100+
nodeControls.Nodes.Add(nodePanel);
93101
nodeControls.Nodes.Add(nodePictureBox);
94102
nodeControls.Nodes.Add(nodeProgressBar);
95103
nodeControls.Nodes.Add(nodeScrollBar);
@@ -104,8 +112,7 @@ public FormExamples()
104112
treeView.Refresh();
105113

106114
// Grip renderer is normal control. Bring it to front if you use it over other controls that can technicaly hide it.
107-
// Unfortunately it will not dock with panel scrollbars.
108-
uwfSizeGripRenderer.BringToFront();
115+
// uwfSizeGripRenderer.BringToFront();
109116
}
110117

111118
private void TreeViewOnNodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
@@ -127,14 +134,12 @@ private void TreeViewOnNodeMouseClick(object sender, TreeNodeMouseClickEventArgs
127134
currentPanel = panel;
128135
currentPanel.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
129136
currentPanel.Location = new Point(treeView.Location.X + treeView.Width, uwfHeaderHeight);
130-
currentPanel.Height = Height - uwfHeaderHeight;
137+
currentPanel.Height = Height - uwfHeaderHeight - 16; // We don't want to hide SizeGripRenderer with scrollbars.
131138
currentPanel.Width = Width - treeView.Width;
132139

133140
Controls.Add(currentPanel);
134141

135142
currentPanel.Initialize();
136-
137-
uwfSizeGripRenderer.BringToFront();
138143
}
139144
}
140145
}

Examples/Panels/PanelPanel.cs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
namespace UnityWinForms.Examples.Panels
2+
{
3+
using System;
4+
using System.Linq;
5+
using System.Windows.Forms;
6+
7+
public class PanelPanel : BaseExamplePanel
8+
{
9+
public override void Initialize()
10+
{
11+
var panel = this.Create<Panel>();
12+
panel.BorderStyle = BorderStyle.Fixed3D;
13+
14+
for (int i = 0; i < 20; i++)
15+
{
16+
panel.Create<Label>("label" + i);
17+
panel.Create<Button>("button" + i, true, 32);
18+
}
19+
20+
var checkBoxAutoscroll = this.Create<CheckBox>("AutoScroll", false, 8, panel.Height + 8);
21+
checkBoxAutoscroll.CheckedChanged += (sender, args) => { panel.AutoScroll = checkBoxAutoscroll.Checked; };
22+
23+
var borderStyles = Enum.GetNames(typeof(BorderStyle)).Cast<object>().ToArray();
24+
25+
this.Create<Label>("BorderStyle:", false, 8, lineOffset);
26+
var comboBorder = this.Create<ComboBox>();
27+
comboBorder.Items.AddRange(borderStyles);
28+
comboBorder.SelectedIndex = 2;
29+
comboBorder.SelectedIndexChanged += (sender, args) =>
30+
{
31+
var selectedItem = comboBorder.SelectedItem.ToString();
32+
panel.BorderStyle = (BorderStyle)Enum.Parse(typeof(BorderStyle), selectedItem);
33+
};
34+
}
35+
}
36+
}

Examples/Panels/PanelProgressBar.cs

+19-5
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,31 @@ public class PanelProgressBar : BaseExamplePanel
88

99
public override void Initialize()
1010
{
11-
var progressBar = this.Create<ProgressBar>();
12-
progressBar.Style = ProgressBarStyle.Marquee;
11+
var labelMarqueeText = "Marguee. Value: ";
12+
var labelMarquee = this.Create<Label>(labelMarqueeText);
13+
14+
var progressBarMarquee = this.Create<ProgressBar>();
15+
progressBarMarquee.Style = ProgressBarStyle.Marquee;
16+
17+
var labelBlocksText = "Blocks. Value: ";
18+
var labelBlocks = this.Create<Label>(labelBlocksText, false, 8, lineOffset);
19+
20+
var progressBarBlocks = this.Create<ProgressBar>();
21+
progressBarBlocks.Style = ProgressBarStyle.Blocks;
1322

1423
timer = new Timer();
1524
timer.Interval = 100;
1625
timer.Tick += (sender, args) =>
1726
{
18-
var nextValue = progressBar.Value + 1;
19-
if (nextValue > progressBar.Maximum)
27+
var nextValue = progressBarMarquee.Value + 1;
28+
if (nextValue > progressBarMarquee.Maximum)
2029
nextValue = 0;
21-
progressBar.Value = nextValue;
30+
31+
progressBarMarquee.Value = nextValue;
32+
progressBarBlocks.Value = nextValue;
33+
34+
labelMarquee.Text = labelMarqueeText + progressBarMarquee.Value;
35+
labelBlocks.Text = labelBlocksText + progressBarBlocks.Value;
2236
};
2337
timer.Start();
2438
}

System/Windows/Forms/FileDialog.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,8 @@ public FileRenderer(FileDialog owner)
318318

319319
filesTree = new TreeView();
320320
filesTree.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
321-
filesTree.BorderColor = Color.LightGray;
322321
filesTree.Size = new Drawing.Size(Width, Height);
323-
filesTree.SelectedNodeChanged += filesTree_SelectedNodeChanged;
322+
filesTree.AfterSelect += filesTree_SelectedNodeChanged;
324323
filesTree.NodeMouseDoubleClick += filesTree_NodeMouseDoubleClick;
325324
Controls.Add(filesTree);
326325

System/Windows/Forms/Panel.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ protected override Size DefaultSize
1616
get { return new Size(200, 100); }
1717
}
1818

19-
protected override void OnPaint(PaintEventArgs e)
19+
protected internal override void uwfOnLatePaint(PaintEventArgs e)
2020
{
21+
base.uwfOnLatePaint(e);
22+
2123
ControlPaint.PrintBorder(e.Graphics, ClientRectangle, BorderStyle, Border3DStyle.Sunken);
2224
}
2325
}

System/Windows/Forms/ProgressBar.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ public class ProgressBar : Control
77
{
88
private readonly SolidBrush backBrush = new SolidBrush(SystemColors.ControlLight);
99
private readonly SolidBrush barBrush = new SolidBrush(Color.FromArgb(6, 176, 37));
10+
private readonly SolidBrush barBrushLight1 = new SolidBrush(Color.FromArgb(83, 200, 105));
11+
private readonly SolidBrush barBrushLight2 = new SolidBrush(Color.FromArgb(43, 188, 69));
1012
private readonly Pen borderPen = new Pen(SystemColors.ActiveBorder);
1113
private readonly Color defaultProgressForeColor = SystemColors.Highlight;
1214

@@ -160,6 +162,8 @@ protected override void OnPaint(PaintEventArgs e)
160162
g.FillRectangle(backBrush, 0, 0, Width, Height);
161163
g.DrawRectangle(borderPen, 0, 0, Width, Height);
162164
g.FillRectangle(barBrush, barX, 1, barWidth, Height - 2);
165+
g.FillRectangle(barBrushLight1, barX, Height - 3, barWidth, 3);
166+
g.FillRectangle(barBrushLight2, barX, Height - 5, barWidth, 2);
163167
}
164168
protected override void OnResize(EventArgs e)
165169
{
@@ -191,7 +195,7 @@ private void ApplicationOnUpdateEvent()
191195
}
192196

193197
barX = 0;
194-
barWidth = MathHelper.Step(barWidth, (value / maximum) * Width, 200);
198+
barWidth = (value / (float)maximum) * Width;
195199
updatePos = false;
196200
}
197201
private void UpdatePos()

System/Windows/Forms/ScrollableControl.cs

+36-15
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ public ScrollableControl()
3030
public virtual bool AutoScroll
3131
{
3232
get { return GetScrollState(ScrollStateAutoScrolling); }
33-
set { SetScrollState(ScrollStateAutoScrolling, value); }
33+
set
34+
{
35+
SetScrollState(ScrollStateAutoScrolling, value);
36+
PerformLayout();
37+
}
3438
}
3539
public override Rectangle DisplayRectangle
3640
{
@@ -113,13 +117,15 @@ internal void Native_EnableScrollBar(bool enable, int orientation)
113117
{
114118
if (oriV && vscroll != null)
115119
{
120+
vscroll.Value = 0; // Reset view.
116121
vscroll.ValueChanged -= Scroll_ValueChanged;
117122
vscroll.Dispose();
118123
vscroll = null;
119124
}
120125

121126
if (oriH && hscroll != null)
122127
{
128+
hscroll.Value = 0; // Reset view.
123129
hscroll.ValueChanged -= Scroll_ValueChanged;
124130
hscroll.Dispose();
125131
hscroll = null;
@@ -137,6 +143,22 @@ internal ScrollBar GetScrollBar(int orientation)
137143
return null;
138144
}
139145

146+
protected internal override void uwfOnLatePaint(PaintEventArgs e)
147+
{
148+
if (this is Form)
149+
return;
150+
if (vscroll == null || hscroll == null)
151+
return;
152+
153+
// Fill rect between two scrollbars.
154+
var rx = hscroll.Location.X + hscroll.Width;
155+
var ry = vscroll.Location.Y + vscroll.Height;
156+
var rw = Width - rx;
157+
var rh = Height - ry;
158+
159+
e.Graphics.uwfFillRectangle(vscroll.BackColor, rx, ry, rw, rh);
160+
}
161+
140162
protected bool GetScrollState(int bit)
141163
{
142164
return (bit & scrollState) == bit;
@@ -223,9 +245,8 @@ private void UpdateScrolls()
223245
var autoScroll = (scrollState & ScrollStateAutoScrolling) != 0;
224246
if (autoScroll == false)
225247
{
226-
HorizontalScroll.UpdateScrollInfo();
227-
VerticalScroll.UpdateScrollInfo();
228-
UpdateScrollRects();
248+
Native_EnableScrollBar(false, NativeMethods.SB_VERT);
249+
Native_EnableScrollBar(false, NativeMethods.SB_HORZ);
229250
return;
230251
}
231252

@@ -258,7 +279,6 @@ private void UpdateScrolls()
258279

259280
UpdateScrollRects();
260281
}
261-
262282
private void UpdateScrollRects()
263283
{
264284
var hRightOffset = 0;
@@ -279,26 +299,27 @@ private void UpdateScrollRects()
279299
gripOriginLocation.Offset(-vscroll.Width, 0);
280300
if (hscroll != null && vscroll == null)
281301
gripOriginLocation.Offset(0, -hscroll.Height);
282-
if (vscroll != null && hscroll != null)
283-
{
284-
hRightOffset += 14; // img.Width + bottomRight offset
285-
vBottomOffset += 14;
286-
}
287-
302+
288303
form.uwfSizeGripRenderer.Location = gripOriginLocation;
289304
}
290305
}
291306

307+
if (vscroll != null && hscroll != null)
308+
{
309+
hRightOffset += 14;
310+
vBottomOffset += 14;
311+
}
312+
292313
if (vscroll != null)
293314
{
294-
vscroll.Location = new Point(Width - vscroll.Width, vTopOffset);
295-
vscroll.Height = Height - vTopOffset - vBottomOffset;
315+
vscroll.Location = new Point(Width - vscroll.Width - 1, vTopOffset - 1);
316+
vscroll.Height = Height - vTopOffset - vBottomOffset - 2;
296317
}
297318

298319
if (hscroll != null)
299320
{
300-
hscroll.Location = new Point(0, Height - hscroll.Height);
301-
hscroll.Width = Width - hRightOffset;
321+
hscroll.Location = new Point(1, Height - hscroll.Height - 1);
322+
hscroll.Width = Width - hRightOffset - 2;
302323
}
303324
}
304325
}

0 commit comments

Comments
 (0)