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: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198:
| using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Drawing.Drawing2D;
namespace Studienarbeit_v1 { public partial class frmSpeedometer : Form { public frmSpeedometer() { InitializeComponent(); }
private void frmSpeedometer_Load(object sender, EventArgs e) {
}
private void numMin_ValueChanged(object sender, EventArgs e) { trkBar.Minimum = (int)(numMin.Value); ticks(); Refresh(); }
private void numMax_ValueChanged(object sender, EventArgs e) { trkBar.Maximum = (int)(numMax.Value); ticks(); Refresh(); }
private void numPos_ValueChanged(object sender, EventArgs e) { ticks(); Refresh(); }
private void chkboxBalkenanzeige_CheckedChanged(object sender, EventArgs e) { if (chkboxBalkenanzeige.CheckState == CheckState.Checked) { prgBalken.Visible = true; } else { prgBalken.Visible = false; } }
private void chkboxZahlenangabe_CheckedChanged(object sender, EventArgs e) { if (chkboxZahlenangabe.CheckState == CheckState.Checked) { txtboxAnzeige.Visible = true; } else { txtboxAnzeige.Visible = false; } }
private void chkboxPositionswerte_CheckedChanged(object sender, EventArgs e) { Refresh(); }
private void trkBar_Scroll(object sender, EventArgs e) { txtboxAnzeige.Text = "" + trkBar.Value; prgBalken.Minimum = trkBar.Minimum; prgBalken.Maximum = trkBar.Maximum; prgBalken.Value = trkBar.Value; Refresh(); }
private void FrmSpeedometer_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { tachoDraw(e.Graphics, 0, 0, groupBoxAnzeige.Width - 20, groupBoxAnzeige.Height - 120); }
private void tachoDraw(Graphics gr, int left, int top, int width, int height) { float dotRad = 0.01f;
Brush brush = new SolidBrush(this.ForeColor); Pen pen = new Pen(brush); Font drawFont = new Font("Arial", 12);
pen.Width = 2.5f; gr.DrawEllipse(pen, left + 8, top + 15, width, height);
gr.FillEllipse(brush, (float)(left + 8 + width / 2 - 3), (float)(top + 15 + height / 2 - 3), 6, 6);
gr.TranslateTransform((float)(left + 8 + width / 2), (float)(top + 15 + height / 2)); gr.ScaleTransform(width, height);
gr.RotateTransform(150);
for (int ticks = 0; ticks < numPos.Value; ticks++) {
gr.FillRectangle(brush, 0.5f - 4 * dotRad, -dotRad, 4 * dotRad, 2 * dotRad); gr.RotateTransform(240f / ((float)(numPos.Value - 1))); }
gr.RotateTransform(330);
pointerDraw(gr, brush, -10f, 1f);
gr.ResetTransform(); }
private void pointerDraw(Graphics gr, Brush brush, float pos, float relLength) { GraphicsState grState = gr.Save();
gr.RotateTransform(((int)(240 * (trkBar.Value / (numMax.Value - numMin.Value)) + 120)));
gr.FillPolygon(brush, new PointF[]{ new PointF(0,0), new PointF(0.05f, 0.02f), new PointF(0.2f, 0.005f), new PointF(0.5f, 0.005f), new PointF(0.5f, -0.005f), new PointF(0.2f, -0.005f), new PointF(0.05f,-0.02f), new PointF(0,0)});
gr.Restore(grState);
} private void ticks() { trkBar.TickFrequency = (int)(((float)(trkBar.Maximum - trkBar.Minimum) / (float)numPos.Value)); if (trkBar.TickFrequency >= 20) trkBar.TickFrequency = 20; }
private void groupBoxAnzeige_Enter(object sender, EventArgs e) {
}
private void chkClock_CheckedChanged(object sender, EventArgs e) { if (chkClock.CheckState == CheckState.Checked) { txtboxClock.Visible = true; } else { txtboxClock.Visible = false; } }
private void txtboxClock_TextChanged(object sender, EventArgs e) {
}
private void timer1_Tick_1(object sender, EventArgs e) { txtboxClock.Text = DateTime.Now.ToString(); Invalidate(); Update(); }
private void butExit_Click(object sender, EventArgs e) { Application.Exit(); } } } |