4 using System.Collections;
7 using System.Collections.Generic;
8 using System.ComponentModel;
9 using System.Diagnostics;
13 using System.Threading;
14 using System.Threading.Tasks;
18 using System.Windows.Controls;
19 using System.Windows.Data;
20 using System.Windows.Documents;
21 using System.Windows.Input;
22 using System.Windows.Media;
23 using System.Windows.Media.Imaging;
24 using System.Windows.Navigation;
25 using System.Windows.Shapes;
26 using System.Windows.Threading;
28 using System.Xml.Serialization;
37 public partial class UserControl1 : UserControl
74 BezierSegment
bezier =
new BezierSegment();
77 PathFigure
figure =
new PathFigure();
92 System.Windows.Shapes.Path
myPath =
new System.Windows.Shapes.Path();
96 System.Windows.Shapes.Path
controlPath =
new System.Windows.Shapes.Path();
140 myControl.Visibility = Visibility.Hidden;
147 myControl.Visibility = Visibility.Visible;
273 if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
279 else if (e.Key == Key.V)
290 if (MessageBox.Show(
"你確定要清除畫布嗎? 若要你的檔案將會全部遺失!",
"警告", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
336 myLine.HorizontalAlignment = HorizontalAlignment.Left;
337 myLine.VerticalAlignment = VerticalAlignment.Center;
350 myLine.HorizontalAlignment = HorizontalAlignment.Left;
351 myLine.VerticalAlignment = VerticalAlignment.Center;
456 String tempStr = Data;
457 int tmpMSeat = tempStr.IndexOf(
"M");
458 tempStr = tempStr.Remove(tmpMSeat, 1);
460 String[] tempAry = tempStr.Split(
'C');
461 tempStr = tempAry[0] +
"," + tempAry[1];
471 XmlSerializer serializer =
new XmlSerializer(typeof(
SVGRoot));
472 using (MemoryStream ms =
new MemoryStream(System.Text.Encoding.UTF8.GetBytes(xml)))
486 int margin = (int)
mygrid.Margin.Left;
487 int width = (
int)
mygrid.ActualWidth + (int)
mygrid.Margin.Left + (
int)
mygrid.Margin.Right;
488 int height = (int)
mygrid.ActualHeight + (
int)
mygrid.Margin.Top + (int)
mygrid.Margin.Bottom;
489 mygrid.Background =
new SolidColorBrush(Color.FromArgb(255, 255, 0, 255));
491 RenderTargetBitmap rtb =
new RenderTargetBitmap(width, height, 96d, 96d, PixelFormats.Default);
492 DrawingVisual dv =
new DrawingVisual();
493 using (DrawingContext dc = dv.RenderOpen())
495 Rect r =
new Rect(
new System.Windows.Point(0, 0),
new System.Windows.Size(width, height));
497 dc.DrawRectangle(
new SolidColorBrush(Colors.White),
new Pen(), r);
498 VisualBrush vb =
new VisualBrush(
mygrid);
500 vb.Stretch = Stretch.UniformToFill;
501 dc.DrawRectangle(vb,
null, r);
506 BmpBitmapEncoder encoder =
new BmpBitmapEncoder();
507 encoder.Frames.Add(BitmapFrame.Create(rtb));
509 using (MemoryStream ms =
new MemoryStream())
514 bitmapBytes = ms.ToArray();
521 using (MemoryStream stream =
new MemoryStream())
524 XmlSerializer s =
new XmlSerializer(typeof(
SVGRoot));
529 stream.Seek(0, SeekOrigin.Begin);
531 StreamReader sr =
new StreamReader(stream);
532 string myStr = sr.ReadToEnd();
534 _utility.
xml = myStr;
void InitializeComponent()
InitializeComponent
internal void AddPictureContentControl(Utility _utility)
void hiddenCanvas()
隱藏myControl
void UserControl_KeyDown(object sender, KeyEventArgs e)
繪製曲線
internal System.Windows.Controls.Canvas myBackground
void drawBackLine(double w, double h, double opac)
畫背景格線
使UNIX上開發的C程式移植到windows上 /summary>
void stroke(int stroketype)
BezierSegment bezier
紀錄四個控制點使用
System.Windows.Shapes.Path myPath
static internal ThisAddIn ThisAddIn
System.Windows.Shapes.Path controlPath
紀錄曲線
internal System.Windows.Controls.Canvas mygrid
String pathDataToPoint(String Data)
調整顏色
internal System.Windows.Controls.Canvas myControl
Point correctPoint(Point p)
是否有選取物件 ///
void UserControl_Unloaded(object sender, RoutedEventArgs e)
關閉時,轉成圖片
void initpath(string xml)
void showCanvas()
顯示myControl