const string DOCUMENT_FORMAT_OPEN_XML = "DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
AppDomain.CurrentDomain.AssemblyResolve += (sender, e) =>
{
switch (e.Name)
{
case DOCUMENT_FORMAT_OPEN_XML: return Assembly.Load(Properties.Resources.DocumentFormat_OpenXml);
default: return null;
}
};
Application.Run(new MainFrom());
}
using System.Text;
using System.Threading.Tasks;
using System.IO.Ports;
using System.Windows.Forms;
namespace serialport_process
{
class Program
{
class OutputForm : Form
{
public RichTextBox richTextBox {get ;private set;}
public OutputForm()
{
WindowState = FormWindowState.Maximized;
richTextBox = new RichTextBox
{
Dock = DockStyle.Fill
};
}
}
static Encoding ENCODING = Encoding.ASCII;
const int BUFFER_SIZE = 4096;
static byte[] buffer = new byte[BUFFER_SIZE];
delegate void AppendText(string inText);
static void Main(string[] args)
{
var form = new OutputForm();
var task = new Task(() =>
{
var serialPort = new SerialPort("COM1", 115200, Parity.None, 8, StopBits.Two);
serialPort.DataReceived += (sender, e) =>
{
var count = serialPort.BytesToRead;
while (count > 0)
{
var current_count = serialPort.Read(buffer, 0, count < BUFFER_SIZE ? count : BUFFER_SIZE);
var text = ENCODING.GetString(buffer, 0, current_count);
count -= current_count;
form.Invoke((AppendText)(txt => form.richTextBox.AppendText(txt)), text);
}
};
serialPort.Open();
while (true) ;
});
form.Load += (sender, e) => task.Start();
Application.Run(form);
}
}
}
static IEnumerable<string> Compare<T>(T a, T b)
where T : class
{
return typeof(T)
.GetProperties()
.Where(pi => !pi.GetValue(a, null).Equals(pi.GetValue(b, null)))
.Select(pi=>pi.Name);
}
protected override void OnMouseWheel(MouseEventArgs e)
{
if (isAllowTransfom)
{
var transform_local = transform.Clone();
var matrixOrder = MatrixOrder.Append;
var K = e.Delta > 0 ? SCALE_MUL : 1 / SCALE_MUL;
transform_local.Multiply(new Matrix(1, 0, 0, 1, -e.Location.X, -e.Location.Y), matrixOrder);
transform_local.Multiply(new Matrix(K, 0, 0, K, 0, 0), matrixOrder);
transform_local.Multiply(new Matrix(1, 0, 0, 1, e.Location.X, e.Location.Y), matrixOrder);
transform = transform_local;
OnViewWindowChanged(transform);
}
base.OnMouseWheel(GetWorldMouseEventArgs(e));
}
string _StateValue;
public string stateValue
{
get {return _StateValue; }
set
{
_StateValue = value;
OnStateValueChanged(value); //этот метод генерирует событие на которое подписаны все кому интересно изменения этого поля, например при изменении поля могут по событию перерисовываться форма
}
}
string _CaсhedValue = null;
string cachedValue
{
get
{
if (_CachedValue == null)
{
_CachedValue = CreateValue(); //этот метод вычисляет значение
}
return _CachedValue;
}
}
PointF _Start;
PointF _Stop;
PointF center
{
get
{
return new PointF((_Start.X+_Stop.X)/2,(_Start.Y+_Stop.Y)/2);
}
}
var d = 5D;
using System;
namespace answer
{
using System;
public abstract class MyBaseClass<T, T2>
where T : class, new()
where T2: class, new()
{
protected T RealObject = new T();
public void setRealObject(dynamic realObject) { this.RealObject = realObject; }
public static U CreateFromBaseObject<U>(T baseObject) where U : MyBaseClass<T>, new()
{
var t = new U(); t.setRealObject(baseObject); return t;
}
public static T2 CreateFromBaseObject(T baseObject)
{
return CreateFromBaseObject<T2>(baseObject);
}
}
public class RealDerivedClass {}
public class MyDerivedClass : MyBaseClass<RealDerivedClass, MyDerivedClass>{}
public class Test
{
public static void Main()
{
RealDerivedClass realDerivedClass = new RealDerivedClass();
//Приходится так:
MyDerivedClass myRealDerivedClass = MyDerivedClass.CreateFromBaseObject<MyDerivedClass>(realDerivedClass);
//А хочется так:
MyDerivedClass myRealDerivedClass2 = MyDerivedClass.CreateFromBaseObject(realDerivedClass);
}
}
}
public class DrawingAreaControl : UserControl
{
public DrawingAreaControl()
{
DoubleBuffered = true;
transform = new Matrix();
}
public Matrix transform { get; set; }
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.Transform = transform;
base.OnPaint(e);
}
const float SCALE_MUL = 1.05f;
protected override void OnMouseWheel(MouseEventArgs e)
{
base.OnMouseWheel(e);
var matrixOrder = MatrixOrder.Append;
var K = e.Delta > 0 ? SCALE_MUL : 1 / SCALE_MUL;
transform.Multiply(new Matrix(1, 0, 0, 1, -e.Location.X, -e.Location.Y), matrixOrder);
transform.Multiply(new Matrix(K, 0, 0, K, 0, 0), matrixOrder);
transform.Multiply(new Matrix(1, 0, 0, 1, e.Location.X, e.Location.Y), matrixOrder);
Invalidate();
}
}