My Project
ShapeText.cs
查看本檔案說明文件.
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using System.Drawing;
5 using System.Linq;
6 using System.Text;
7 using System.Threading.Tasks;
8 using System.Windows;
9 using System.Windows.Controls;
10 using System.Windows.Forms;
11 using System.Windows.Input;
12 using System.Windows.Media;
13 using System.Windows.Shapes;
14 
15 
16 namespace ShapeLib.VShape
17 {
18 
19  public class ShapeText : ShapeObj
20  {
21 
22  String txt;
23  System.Windows.Controls.TextBox textBox = new System.Windows.Controls.TextBox();
24  double x, y;
25  byte r, g, b;
26  Boolean last = false;
27  public override System.Collections.ArrayList getMenuItem()
28  {
29  ArrayList ret = new ArrayList();
30  shapeUI ui = new shapeUI();
31  ui.label = "Text";
32  System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetExecutingAssembly();
33  System.IO.Stream myStream = myAssembly.GetManifestResourceStream("ShapeLib.icons.text.png");
34  ui.image = new System.Drawing.Bitmap(myStream);
35 
36 
37  ui.belong = "Shapes";
38  ui.click = this.btn_Click;
39  ret.Add(ui);
40 
41  return ret;
42  //throw new NotImplementedException();
43  }
44  //public override void FormKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
45  //{
46  // txt += e.Key.ToString();
47 
48  //}
49 
50  public override void MouseDownInsert(object sender, System.Windows.Input.MouseButtonEventArgs e)
51  //public void LeftButtonDown(object sender, MouseButtonEventArgs e)
52  {
53  base.MouseDownInsert(sender, e);
54  finish();
55 
56  }
57  public override void finish()
58  {
59 
60  int scale = shapeLib.Data.strokeT;
61  txt = textBox.Text ;
62  TextBlock textBlock = new TextBlock();
63  textBlock.Foreground = new SolidColorBrush(System.Windows.Media.Color.FromRgb(r, g, b));
64  textBlock.Height = textBox.Height;
65  textBlock.Width = textBox.Width;
66  textBlock.FontSize = 10 + scale * 4;
67 
68  Canvas.SetLeft(textBlock, x);
69  Canvas.SetTop(textBlock, y);
70 
71  while (txt.Contains(@"\u" ))
72  {
73  int ind = txt.IndexOf(@"\u");
74  string s= txt.Substring(ind, 6);
75  byte[] bytes = new byte[2];
76  bytes[1] = Convert.ToByte(s.Substring(2, 2), 16);
77  bytes[0] = Convert.ToByte(s.Substring(4, 2), 16);
78  string result = Encoding.Unicode.GetString(bytes);
79  txt=txt.Replace(s, result);
80 
81 
82 
83 
84  }
85  textBlock.Text = txt;
86  shapeLib.Data.mygrid.Children.Add(textBlock);
87  textBox.Text = null;
88  txt = null;
89  shapeLib.Data.mygrid.Children.Remove(textBox);
90  last = true;
91  shapeLib.Data.Root.Focus();
92 
93 
94  }
95  //public void RightButtonDown(object sender, MouseButtonEventArgs e)
96  //{
97  // shapeLib.Data.mygrid.Children.Remove(textBox);
98 
99  //}
100 
101  public override void DrawShape(gView gv, gPath data, Boolean bfirst)
102  {
103  if (bfirst)
104  {
105 
106  shapeLib.Data.Status = "rest";
107  shapeLib.Data.bfirst = false;
108 
109  if (txt == null)
110  {
111  x = data.controlBtn1.X;
112  y = data.controlBtn1.Y;
113  r = data.state.colorR;
114  g = data.state.colorG;
115  b = data.state.colorB;
116  textBox.Foreground = new SolidColorBrush(System.Windows.Media.Color.FromRgb(r, g, b));
117  Canvas.SetLeft(textBox, x);
118  Canvas.SetTop(textBox, y);
119  textBox.FontSize = 10 + shapeLib.Data.strokeT * 4;
120  shapeLib.Data.mygrid.Children.Add(textBox);
121  textBox.Focus();
122  textBox.AcceptsReturn = true;
123  textBox.AcceptsTab = true;
124  txt = textBox.Text;
125  last = false;
126  // shapeLib.Data.mygrid.MouseDown += this.MouseDownInsert;
127  //new System.Windows.Input.MouseButtonEventHandler(LeftButtonDown);
128 
129  }
130  else if (!last)
131  {
132  txt = null;
133  textBox.Focus();
134 
135  }
136  }else
137 
138 
139  txt = null;
140 
141 
142  }
143  }
144 
145 }
static GModel Data
Definition: shapeLib.cs:42
RibbonControlEventHandler click
Definition: ShapeObj.cs:49
System.Windows.Controls.TextBox textBox
Definition: ShapeText.cs:23
string belong
判斷按下Button控制項
Definition: ShapeObj.cs:53
override void DrawShape(gView gv, gPath data, Boolean bfirst)
依data 繪製,如果是第一次畫要新建shape, 更新的話只要更新最後一點
Definition: ShapeText.cs:101
override void finish()
Definition: ShapeText.cs:57
override void MouseDownInsert(object sender, System.Windows.Input.MouseButtonEventArgs e)
Definition: ShapeText.cs:50
某一類的形狀.包含UI 的界面,繪製方式.更新方式.新增方式
Definition: ShapeObj.cs:59
定義一個UI項目
Definition: ShapeObj.cs:42
override System.Collections.ArrayList getMenuItem()
覆寫System.Collections.ArrayList
Definition: ShapeText.cs:27
System.Windows.Point controlBtn1
Definition: GraphDoc.cs:253
void btn_Click(object sender, RibbonControlEventArgs e)
UI 點選
Definition: ShapeObj.cs:107
System.Windows.Controls.UserControl Root
Definition: shapeLib.cs:122
System.Drawing.Image image
Definition: ShapeObj.cs:46