forked from thedeemon/gep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenerateCodeGfxForm.cs
73 lines (65 loc) · 2.23 KB
/
GenerateCodeGfxForm.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace gep
{
partial class GenerateCodeGfxForm : Form
{
public GenerateCodeGfxForm(string code)
{
InitializeComponent();
using (var ff = new FontFamily(System.Drawing.Text.GenericFontFamilies.Monospace))
using (var font = new Font(ff, 10, FontStyle.Regular))
using (Graphics og = CreateGraphics())
{
Size sz = og.MeasureString(code, font).ToSize();
Bitmap bmp = new Bitmap(sz.Width, sz.Height);
Graphics g = Graphics.FromImage(bmp);
g.FillRectangle(Brushes.White, 0, 0, sz.Width, sz.Height);
g.DrawString(code, font, Brushes.Black, 0, 0);
g.Dispose();
vScrollBar.Maximum = sz.Height;
vScrollBar.SmallChange = sz.Height / 10;
vScrollBar.LargeChange = panel.Size.Height;//sz.Height / 4;
panel.bmp = bmp;
}
}
private void vScrollBar_ValueChanged(object sender, EventArgs e)
{
panel.dy = -vScrollBar.Value;
panel.Invalidate();
}
private void OnRegister(object sender, EventArgs e)
{
using(var f = new RegisterForm())
f.ShowDialog();
}
}
class CodePanel : Panel
{
public Bitmap bmp;
public int dy = 0;
protected override void OnPaintBackground(PaintEventArgs e)
{
if (bmp != null)
{
Rectangle rc = ClientRectangle;
Size sz = bmp.Size;
rc.X += sz.Width;
e.Graphics.FillRectangle(Brushes.White, rc);
rc = ClientRectangle;
rc.Y += sz.Height + dy;
e.Graphics.FillRectangle(Brushes.White, rc);
}
}
protected override void OnPaint(PaintEventArgs e)
{
if (bmp != null)
e.Graphics.DrawImageUnscaled(bmp, 0, dy);
}
}
}