aboutsummaryrefslogtreecommitdiff
path: root/Histacom2.Engine/UI
diff options
context:
space:
mode:
authorAlex-TIMEHACK <[email protected]>2017-10-24 13:50:38 +0100
committerAlex-TIMEHACK <[email protected]>2017-10-24 13:50:38 +0100
commit72a2b98a29ac1d3b67a4158b6a1823a39ecb5e00 (patch)
tree8a39e99f1542fc0335a4553231fea5acdb9beb70 /Histacom2.Engine/UI
parent3d2e297b43cbd7f99269c9a58b25651a83ccef3c (diff)
downloadhistacom2-72a2b98a29ac1d3b67a4158b6a1823a39ecb5e00.tar.gz
histacom2-72a2b98a29ac1d3b67a4158b6a1823a39ecb5e00.tar.bz2
histacom2-72a2b98a29ac1d3b67a4158b6a1823a39ecb5e00.zip
Finished ClassicTextBox
ClassicDropDown next!
Diffstat (limited to 'Histacom2.Engine/UI')
-rw-r--r--Histacom2.Engine/UI/ClassicDropDown.Designer.cs7
-rw-r--r--Histacom2.Engine/UI/ClassicDropDown.cs294
-rw-r--r--Histacom2.Engine/UI/ClassicTextBox.Designer.cs2
-rw-r--r--Histacom2.Engine/UI/ClassicTextbox.cs7
4 files changed, 11 insertions, 299 deletions
diff --git a/Histacom2.Engine/UI/ClassicDropDown.Designer.cs b/Histacom2.Engine/UI/ClassicDropDown.Designer.cs
index 2925f72..424ff69 100644
--- a/Histacom2.Engine/UI/ClassicDropDown.Designer.cs
+++ b/Histacom2.Engine/UI/ClassicDropDown.Designer.cs
@@ -2,7 +2,7 @@
{
partial class ClassicDropDown
{
- /// <summary>
+ /// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
@@ -22,13 +22,14 @@
#region Component Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
+ /// <summary>
+ /// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
}
#endregion
diff --git a/Histacom2.Engine/UI/ClassicDropDown.cs b/Histacom2.Engine/UI/ClassicDropDown.cs
index 85c509a..43e1a65 100644
--- a/Histacom2.Engine/UI/ClassicDropDown.cs
+++ b/Histacom2.Engine/UI/ClassicDropDown.cs
@@ -1,306 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
-using System.Diagnostics;
using System.Drawing;
+using System.Data;
using System.Linq;
-using System.Reflection;
-using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Histacom2.Engine.UI
{
- //public class CustomTextBox : NativeWindow
- //{
- // private TextBox parentTextBox;
- // private Bitmap bitmap;
- // private Graphics textBoxGraphics;
- // private Graphics bufferGraphics;
- // // this is where we intercept the Paint event for the TextBox at the OS level  
- // protected override void WndProc(ref Message m)
- // {
- // switch (m.Msg)
- // {
- // case 15: // this is the WM_PAINT message  
- // // invalidate the TextBox so that it gets refreshed properly  
- // parentTextBox.Invalidate();
- // // call the default win32 Paint method for the TextBox first  
- // base.WndProc(ref m);
- // // now use our code to draw extra stuff over the TextBox  
- // this.CustomPaint();
- // break;
- // default:
- // base.WndProc(ref m);
- // break;
- // }
- // }
- // public CustomTextBox(TextBox textBox)
- // {
- // this.parentTextBox = textBox;
- // this.bitmap = new Bitmap(textBox.Width, textBox.Height);
- // this.bufferGraphics = Graphics.FromImage(this.bitmap);
- // this.bufferGraphics.Clip = new Region(textBox.ClientRectangle);
- // this.textBoxGraphics = Graphics.FromHwnd(textBox.Handle);
- // // Start receiving messages (make sure you call ReleaseHandle on Dispose):  
- // this.AssignHandle(textBox.Handle);
- // }
- // private void CustomPaint()
- // {
- // // code goes here, see below  
- // }
- //}
-
- public partial class ClassicDropDown : Control
+ public partial class ClassicDropDown : UserControl
{
- public TextBox tb = new TextBox();
- public bool UseSystemPasswordChar { get; set; }
- public int CursorPosition { get; set; }
- private Timer CursorBlink { get; set; }
- private bool _cursorVisible { get; set; }
-
- public ClassicDropDown() : base()
- {
- if (SaveSystem.currentTheme != null) Font = SaveSystem.currentTheme.buttonFont;
- else Font = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular);
-
- DoubleBuffered = true;
-
- CursorBlink = new Timer();
- CursorBlink.Interval = 1000;
-
- // The stuff that make the textbox "work"
-
- MouseDown += new MouseEventHandler(PerformMouseDown);
- MouseUp += new MouseEventHandler(PerformMouseUp);
-
- PreviewKeyDown += (s, e) =>
- {
- e.IsInputKey = true;
- };
-
- //KeyDown += new KeyEventHandler(PerformKeyDown);
-
- // Remove the default textbox paint event so that we can have our own! ACTUALLY, NO!
-
- //FieldInfo f1 = typeof(Control).GetField("EventPaint",
- // BindingFlags.Static | BindingFlags.NonPublic);
- //object obj = f1.GetValue(this);
- //PropertyInfo pi = GetType().GetProperty("Events",
- // BindingFlags.NonPublic | BindingFlags.Instance);
- //EventHandlerList list = (EventHandlerList)pi.GetValue(this, null);
- //list.RemoveHandler(obj, list[obj]);
-
- //tb.Paint += new PaintEventHandler(PerformPaint);
- //TextChanged += new EventHandler(PerformTextChanged);
- //CursorBlink.Tick += new EventHandler(PerformCursorBlink);
-
- //CursorBlink.Start();
-
- // I know it's a bit of a hack but it's all we can really do...
- tb.Size = new Size(this.Size.Width - 6, this.Size.Height - 6);
- tb.Location = new Point(3, 3);
- tb.BorderStyle = BorderStyle.None;
- Controls.Add(tb);
-
-
- }
-
- protected override void OnPaint(PaintEventArgs e)
- {
- var textboxcolor = Color.Silver;
- if (SaveSystem.currentTheme != null) textboxcolor = SaveSystem.currentTheme.windowColor;
-
- if (SaveSystem.currentTheme != null) BackColor = SaveSystem.currentTheme.threeDObjectsColor;
- else BackColor = Color.White;
-
- var _lightBack = Paintbrush.GetLightFromColor(textboxcolor);
- var _darkBack = Paintbrush.GetDarkFromColor(textboxcolor);
-
- if (SaveSystem.currentTheme != null) Font = SaveSystem.currentTheme.buttonFont;
- else Font = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular);
-
- var g = e.Graphics;
- g.Clear(BackColor);
-
- //g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
- //if (UseSystemPasswordChar) g.DrawString(new string('●', Text.Length), Font, Brushes.Black, 3, 3);
- //else g.DrawString(Text, Font, Brushes.Black, 3, 3);
-
- g.DrawLine(new Pen(_darkBack), 0, 0, Width - 2, 0);
- g.DrawLine(new Pen(_lightBack), Width - 1, 0, Width - 1, Height - 1);
- g.DrawLine(new Pen(_lightBack), 0, Height - 1, Width - 1, Height - 1);
- g.DrawLine(new Pen(_darkBack), 0, 0, 0, Height - 2);
- g.DrawLine(Pens.Black, 1, 1, Width - 3, 1);
- g.DrawLine(Pens.Black, 1, 1, 1, Height - 3);
- g.DrawLine(new Pen(textboxcolor), 1, Height - 2, Width - 2, Height - 2);
- g.DrawLine(new Pen(textboxcolor), Width - 2, Height - 2, Width - 2, 1);
-
- Size textSize = MeasureText(Text.Substring(0, CursorPosition), Font); // Get the width of the text from the begining to the cursor's position so it can draw the cursor.
-
- if (_cursorVisible) g.DrawLine(new Pen(Color.Gray), textSize.Width + 3, 4, textSize.Width + 3, Height - 4); // This is the caret!
- g.DrawImage(Properties.Resources.ClassicDropDownButton, Width - 17, 2);
-
- base.OnPaint(e);
-
- }
-
- private void PerformMouseDown(object sender, MouseEventArgs e)
- {
- // TextBox:
-
- base.Focus();
-
- // First check if it is in the bounds of the actual box
- if (e.X < Width - 18 && e.X > 3 && e.Y > 3 && e.Y < Width - 2)
- {
- // Now to get where on text you are clicking... this is very tricky because different characters are different widths...
- int Sum = 0;
- int i = 0;
-
- foreach (char character in Text)
- {
-
- Sum += MeasureText(character.ToString(), Font).Width;
-
- if (e.X - 3 <= Sum) break;
-
- //LastSum = Sum;
- i++;
- }
-
- //setCurPos = (Sum == 0) ? Text.Length : Sum;
- //if (setCurPos > Text.Length) setCurPos = Text.Length;
- CursorPosition = i; // This sets the cursor position!
- }
- _cursorVisible = true;
-
- // DropDown:
-
-
- Invalidate();
- }
-
- private void PerformMouseUp(object sender, MouseEventArgs e)
+ public ClassicDropDown()
{
- // DropDown:
-
-
+ InitializeComponent();
}
-
- private void PerformKeyDown(object sender, KeyEventArgs e)
- {
- // TextBox:
-
- switch (e.KeyCode)
- {
- case Keys.Back:
- Text = Text.Remove(CursorPosition - 1, 1);
- break;
- case Keys.Delete:
- if (!(CursorPosition > Text.Length + 1)) Text = Text.Remove(CursorPosition, 1);
- break;
- case Keys.Home:
- CursorPosition = 0;
- break;
- case Keys.End:
- CursorPosition = Text.Length;
- break;
- case Keys.Left:
- if (CursorPosition > 0) CursorPosition -= 1;
- break;
- case Keys.Right:
- if (CursorPosition < Text.Length) CursorPosition += 1;
- break;
- case Keys.Return:
- break;
- case Keys.Space:
- Text = Text.Insert(CursorPosition, " ");
- CursorPosition = CursorPosition + 1;
- break;
- default:
- bool caps = false;
-
- if (e.Shift) caps = true;
- if (Control.IsKeyLocked(Keys.CapsLock)) caps = true;
-
- if (char.IsLetterOrDigit((char)e.KeyCode))
- {
- // Now the numbers 1, 2, 3 etc. are "d1", "d2" etc. - STUPID, RIGHT? So now we have to check if it has a number and contains "d".
-
- bool handled = false;
-
- if (StrContainsNumber(e.KeyCode.ToString().ToLower()))
- {
- if (e.KeyCode.ToString().ToLower().Contains("d"))
- {
- handled = true;
- Text = Text.Insert(CursorPosition, e.KeyCode.ToString().Replace("d", ""));
- }
- }
-
- if (handled == false)
- {
- if (caps == false) Text = Text.Insert(CursorPosition, e.KeyCode.ToString().ToLower()); else Text = Text.Insert(CursorPosition, e.KeyCode.ToString().ToUpper());
- }
- CursorPosition = CursorPosition + 1;
- }
- break;
- }
-
- _cursorVisible = true;
- Invalidate();
- }
-
- private void PerformCursorBlink(object sender, EventArgs e)
- {
- if (_cursorVisible) _cursorVisible = false;
- else _cursorVisible = true;
- Invalidate();
- }
-
- private void PerformTextChanged(object sender, EventArgs e)
- {
- _cursorVisible = true;
- if (CursorPosition >= Text.Length) CursorPosition = Text.Length;
- Invalidate();
- }
-
- public static Size MeasureText(string Text, Font Font)
- {
- TextFormatFlags flags
- = TextFormatFlags.Left
- | TextFormatFlags.Top
- | TextFormatFlags.NoPadding
- | TextFormatFlags.NoPrefix;
- Size szProposed = new Size(int.MaxValue, int.MaxValue);
- Size sz1 = TextRenderer.MeasureText(".", Font, szProposed, flags);
- Size sz2 = TextRenderer.MeasureText(Text + ".", Font, szProposed, flags);
- return new Size(sz2.Width - sz1.Width, sz2.Height);
- }
-
- public bool StrContainsNumber(string str)
- {
- foreach (char ch in str)
- {
- double unused;
- if (double.TryParse(ch.ToString(), out unused)) return true;
- }
- return false;
- }
-
- [DllImport("gdi32.dll")]
- private static extern bool BitBlt(
-IntPtr hdcDest, // handle to destination DC
-int nXDest, // x-coord of destination upper-left corner
-int nYDest, // y-coord of destination upper-left corner
-int nWidth, // width of destination rectangle
-int nHeight, // height of destination rectangle
-IntPtr hdcSrc, // handle to source DC
-int nXSrc, // x-coordinate of source upper-left corner
-int nYSrc, // y-coordinate of source upper-left corner
-System.Int32 dwRop // raster operation code
-);
}
}
diff --git a/Histacom2.Engine/UI/ClassicTextBox.Designer.cs b/Histacom2.Engine/UI/ClassicTextBox.Designer.cs
index 0e7148f..af6b199 100644
--- a/Histacom2.Engine/UI/ClassicTextBox.Designer.cs
+++ b/Histacom2.Engine/UI/ClassicTextBox.Designer.cs
@@ -93,8 +93,6 @@
this.Controls.Add(this.bborder);
this.Controls.Add(this.rborder);
this.Controls.Add(this.lborder);
- this.MaximumSize = new System.Drawing.Size(0, 17);
- this.MinimumSize = new System.Drawing.Size(100, 17);
this.Name = "ClassicTextBox";
this.Size = new System.Drawing.Size(100, 17);
((System.ComponentModel.ISupportInitialize)(this.bborder)).EndInit();
diff --git a/Histacom2.Engine/UI/ClassicTextbox.cs b/Histacom2.Engine/UI/ClassicTextbox.cs
index 8c1d8d8..a42c2b1 100644
--- a/Histacom2.Engine/UI/ClassicTextbox.cs
+++ b/Histacom2.Engine/UI/ClassicTextbox.cs
@@ -30,11 +30,10 @@ namespace Histacom2.Engine.UI
this.Paint += new PaintEventHandler((object sender, PaintEventArgs e) =>
{
// Update a bunch of variables!
- if (SaveSystem.currentTheme != null) textBox1.Font = SaveSystem.currentTheme.buttonFont;
- else textBox1.Font = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular);
+ textBox1.Font = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular);
- if (SaveSystem.currentTheme != null) BackColor = SaveSystem.currentTheme.threeDObjectsColor;
- else BackColor = Color.White;
+ if (SaveSystem.currentTheme != null) textBox1.BackColor = SaveSystem.currentTheme.threeDObjectsColor;
+ else textBox1.BackColor = Color.White;
if (SaveSystem.currentTheme != null)
{