Skip to content

Commit 665d477

Browse files
committed
Moving PictureBox related helpers to the new QuickPictureBox class
1 parent 508906a commit 665d477

File tree

7 files changed

+98
-76
lines changed

7 files changed

+98
-76
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using QuickLibrary;
2+
using System.Drawing;
3+
using System.Windows.Forms;
4+
5+
namespace quick_picture_viewer
6+
{
7+
internal class QuickPictureBox : PictureBox
8+
{
9+
public void ApplyCheckerboardBackground(bool apply, bool darkMode = false)
10+
{
11+
if (!apply)
12+
{
13+
BackgroundImage?.Dispose();
14+
BackgroundImage = null;
15+
return;
16+
}
17+
18+
Color col = darkMode ? Color.FromArgb(76, 76, 76) : Color.FromArgb(191, 191, 191);
19+
Bitmap bmp = new Bitmap(16, 16);
20+
using (SolidBrush brush = new SolidBrush(col))
21+
using (Graphics G = Graphics.FromImage(bmp))
22+
{
23+
G.FillRectangle(brush, 0, 0, 8, 8);
24+
G.FillRectangle(brush, 8, 8, 8, 8);
25+
}
26+
27+
BackgroundImage = bmp;
28+
BackgroundImageLayout = ImageLayout.Tile;
29+
}
30+
31+
public void UpdatePictureBoxLocation(Panel picturePanel)
32+
{
33+
int x, y;
34+
35+
if (Width < picturePanel.Width) x = (int)((double)(picturePanel.Width - Width) / (double)2);
36+
else x = -picturePanel.HorizontalScroll.Value;
37+
38+
if (Height < picturePanel.Height) y = (int)((double)(picturePanel.Height - Height) / (double)2);
39+
else y = -picturePanel.VerticalScroll.Value;
40+
41+
Location = new Point(x, y);
42+
43+
if (picturePanel != null)
44+
{
45+
if (Width > picturePanel.Width && Height > picturePanel.Height) NativeMan.ShowScrollBar(picturePanel.Handle, NativeMan.ScrollBarDirection.SB_BOTH, true);
46+
else if (Width > picturePanel.Width) NativeMan.ShowScrollBar(picturePanel.Handle, NativeMan.ScrollBarDirection.SB_HORZ, true);
47+
else if (Height > picturePanel.Height) NativeMan.ShowScrollBar(picturePanel.Handle, NativeMan.ScrollBarDirection.SB_VERT, true);
48+
else NativeMan.ShowScrollBar(picturePanel.Handle, NativeMan.ScrollBarDirection.SB_BOTH, false);
49+
}
50+
}
51+
}
52+
}

quick-picture-viewer/forms/MainForm.Designer.cs

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

quick-picture-viewer/forms/MainForm.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ private void setZoomFactor(int newZoomFactor)
600600
pictureBox.Invoke((MethodInvoker)(() =>
601601
{
602602
pictureBox.Size = newSize;
603-
MainHelper.UpdatePictureBoxLocation(picturePanel, pictureBox);
603+
pictureBox.UpdatePictureBoxLocation(picturePanel);
604604
}));
605605
}
606606

@@ -695,12 +695,12 @@ public void setCheckboardBackground(bool b, bool saveToDisk)
695695
picturePanel.BackColor = Color.Transparent;
696696
Properties.Settings.Default.BackColor = "";
697697
Properties.Settings.Default.Save();
698-
MainHelper.ApplyCheckerboardBackground(pictureBox, true, darkMode);
698+
pictureBox.ApplyCheckerboardBackground(true, darkMode);
699699
}
700700
}
701701
else
702702
{
703-
MainHelper.ApplyCheckerboardBackground(pictureBox, false);
703+
pictureBox.ApplyCheckerboardBackground(false);
704704
}
705705

706706
if (saveToDisk)
@@ -974,7 +974,7 @@ private void setFullscreen(bool b)
974974
}
975975

976976
picturePanel.BackColor = Color.Black;
977-
MainHelper.ApplyCheckerboardBackground(pictureBox, false, darkMode);
977+
pictureBox.ApplyCheckerboardBackground(false, darkMode);
978978

979979
typeOpsButton.Left = ClientRectangle.Width + 27;
980980
pleaseOpenLabel.ForeColor = Color.White;
@@ -1003,7 +1003,7 @@ private void setFullscreen(bool b)
10031003
if (checkboardBackground)
10041004
{
10051005
picturePanel.BackColor = Color.Transparent;
1006-
MainHelper.ApplyCheckerboardBackground(pictureBox, true, darkMode);
1006+
pictureBox.ApplyCheckerboardBackground(true, darkMode);
10071007
}
10081008
else
10091009
{
@@ -1878,7 +1878,7 @@ private void backCustomBtn_Click(object sender, EventArgs e)
18781878

18791879
private void MainForm_ResizeEnd(object sender, EventArgs e)
18801880
{
1881-
if (!autoZoom) MainHelper.UpdatePictureBoxLocation(picturePanel, pictureBox);
1881+
if (!autoZoom) pictureBox.UpdatePictureBoxLocation(picturePanel);
18821882
}
18831883

18841884
private void zoomTextBox_MouseEnter(object sender, EventArgs e)
@@ -2017,14 +2017,14 @@ private void statusStrip1_VisibleChanged(object sender, EventArgs e)
20172017
{
20182018
showStatusbarBtn.Checked = statusStrip1.Visible;
20192019
UpdatePicturePanelHeight();
2020-
MainHelper.UpdatePictureBoxLocation(picturePanel, pictureBox);
2020+
pictureBox.UpdatePictureBoxLocation(picturePanel);
20212021
}
20222022

20232023
private void toolStrip1_VisibleChanged(object sender, EventArgs e)
20242024
{
20252025
showToolbarBtn.Checked = toolStrip1.Visible;
20262026
UpdatePicturePanelHeight();
2027-
MainHelper.UpdatePictureBoxLocation(picturePanel, pictureBox);
2027+
pictureBox.UpdatePictureBoxLocation(picturePanel);
20282028
}
20292029

20302030
private void showStatusBarBtn_Click(object sender, EventArgs e)
@@ -2179,7 +2179,7 @@ public void cropBtn_Click(object sender, EventArgs e)
21792179
pictureBox.Image = originalImage;
21802180
setImageChanged(true);
21812181
UpdateSizeLabel();
2182-
MainHelper.UpdatePictureBoxLocation(picturePanel, pictureBox);
2182+
pictureBox.UpdatePictureBoxLocation(picturePanel);
21832183

21842184
selectionBtn.Checked = false;
21852185
}

quick-picture-viewer/forms/MiniViewForm.Designer.cs

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

quick-picture-viewer/forms/MiniViewForm.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private void setZoomFactor(int newZoomFactor)
9595

9696
pictureBox.Size = new Size(newWidth, newHeight);
9797

98-
MainHelper.UpdatePictureBoxLocation(picturePanel, pictureBox);
98+
pictureBox.UpdatePictureBoxLocation(picturePanel);
9999
}
100100

101101
private void ZoomToFit()
@@ -157,7 +157,7 @@ private void setCheckboardBackground(bool b)
157157
checkboardBackground = b;
158158
checkboardBtn.Checked = b;
159159
pictureBox.BackColor = checkboardBackground ? ThemeMan.DarkBackColor : Color.Black;
160-
MainHelper.ApplyCheckerboardBackground(pictureBox, b, true);
160+
pictureBox.ApplyCheckerboardBackground(b, true);
161161
}
162162

163163
private void MiniViewForm_KeyDown(object sender, KeyEventArgs e)
@@ -276,7 +276,7 @@ private void picturePanel_MouseMove(object sender, MouseEventArgs e)
276276

277277
private void MiniViewForm_ResizeEnd(object sender, EventArgs e)
278278
{
279-
if (!autoZoom) MainHelper.UpdatePictureBoxLocation(picturePanel, pictureBox);
279+
if (!autoZoom) pictureBox.UpdatePictureBoxLocation(picturePanel);
280280
zoomLabel.ForeColor = Width > 240 ? Color.White : Color.Black;
281281
}
282282

quick-picture-viewer/helpers/MainHelper.cs

-50
This file was deleted.

quick-picture-viewer/quick-picture-viewer.csproj

+30-10
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@
149149
<Reference Include="WindowsFormsIntegration" />
150150
</ItemGroup>
151151
<ItemGroup>
152+
<Compile Include="controls\QuickPictureBox.cs">
153+
<SubType>Component</SubType>
154+
</Compile>
152155
<Compile Include="languages\lang_hr.Designer.cs">
153156
<AutoGen>True</AutoGen>
154157
<DesignTime>True</DesignTime>
@@ -166,9 +169,10 @@
166169
<Compile Include="typewrappers\system\FileTypeMan.cs" />
167170
<Compile Include="typewrappers\system\TypeWrapper.cs" />
168171
<Compile Include="typewrappers\WebpWrapper.cs" />
169-
<Compile Include="helpers\MainHelper.cs" />
170172
<Compile Include="typewrappers\engines\IcoEngine.cs" />
171-
<Compile Include="forms\InfoForm.cs" />
173+
<Compile Include="forms\InfoForm.cs">
174+
<SubType>Form</SubType>
175+
</Compile>
172176
<Compile Include="forms\InfoForm.Designer.cs">
173177
<DependentUpon>InfoForm.cs</DependentUpon>
174178
</Compile>
@@ -208,7 +212,9 @@
208212
<DesignTime>True</DesignTime>
209213
<DependentUpon>lang_ru.resx</DependentUpon>
210214
</Compile>
211-
<Compile Include="forms\MiniViewForm.cs" />
215+
<Compile Include="forms\MiniViewForm.cs">
216+
<SubType>Form</SubType>
217+
</Compile>
212218
<Compile Include="forms\MiniViewForm.Designer.cs">
213219
<DependentUpon>MiniViewForm.cs</DependentUpon>
214220
</Compile>
@@ -223,34 +229,48 @@
223229
<Compile Include="forms\SelectionForm.Designer.cs">
224230
<DependentUpon>SelectionForm.cs</DependentUpon>
225231
</Compile>
226-
<Compile Include="forms\PluginManForm.cs" />
232+
<Compile Include="forms\PluginManForm.cs">
233+
<SubType>Form</SubType>
234+
</Compile>
227235
<Compile Include="forms\PluginManForm.Designer.cs">
228236
<DependentUpon>PluginManForm.cs</DependentUpon>
229237
</Compile>
230238
<Compile Include="typewrappers\SvgWrapper.cs" />
231239
<Compile Include="typewrappers\PsdWrapper.cs" />
232-
<Compile Include="forms\SettingsForm.cs" />
240+
<Compile Include="forms\SettingsForm.cs">
241+
<SubType>Form</SubType>
242+
</Compile>
233243
<Compile Include="forms\SettingsForm.Designer.cs">
234244
<DependentUpon>SettingsForm.cs</DependentUpon>
235245
</Compile>
236246
<Compile Include="helpers\ShellManager.cs" />
237-
<Compile Include="typewrappers\forms\SvgOpsForm.cs" />
247+
<Compile Include="typewrappers\forms\SvgOpsForm.cs">
248+
<SubType>Form</SubType>
249+
</Compile>
238250
<Compile Include="typewrappers\forms\SvgOpsForm.Designer.cs">
239251
<DependentUpon>SvgOpsForm.cs</DependentUpon>
240252
</Compile>
241-
<Compile Include="forms\PrintForm.cs" />
253+
<Compile Include="forms\PrintForm.cs">
254+
<SubType>Form</SubType>
255+
</Compile>
242256
<Compile Include="forms\PrintForm.Designer.cs">
243257
<DependentUpon>PrintForm.cs</DependentUpon>
244258
</Compile>
245-
<Compile Include="forms\EditSelForm.cs" />
259+
<Compile Include="forms\EditSelForm.cs">
260+
<SubType>Form</SubType>
261+
</Compile>
246262
<Compile Include="forms\EditSelForm.Designer.cs">
247263
<DependentUpon>EditSelForm.cs</DependentUpon>
248264
</Compile>
249-
<Compile Include="forms\WallpaperForm.cs" />
265+
<Compile Include="forms\WallpaperForm.cs">
266+
<SubType>Form</SubType>
267+
</Compile>
250268
<Compile Include="forms\WallpaperForm.Designer.cs">
251269
<DependentUpon>WallpaperForm.cs</DependentUpon>
252270
</Compile>
253-
<Compile Include="forms\AboutForm.cs" />
271+
<Compile Include="forms\AboutForm.cs">
272+
<SubType>Form</SubType>
273+
</Compile>
254274
<Compile Include="forms\AboutForm.Designer.cs">
255275
<DependentUpon>AboutForm.cs</DependentUpon>
256276
</Compile>

0 commit comments

Comments
 (0)