form not movable
public partial class Form1 : Form
{
Point defaultLocation;
public Form1()
{
InitializeComponent();
defaultLocation = this.Location;
}
private void Form1_Move(object sender, EventArgs e)
{
this.Location = defaultLocation;
}
}
form not movable
public partial class Form1 : Form
{
Point defaultLocation;
public Form1()
{
InitializeComponent();
defaultLocation = this.Location;
}
private void Form1_Move(object sender, EventArgs e)
{
this.Location = defaultLocation;
}
}
Printing a Bit map image to pos printer via comport in C# [closed]
--
private void button1_Click(object sender, EventArgs e)
{
SerialPort port = new SerialPort("com6", 9100, Parity.None, 8, StopBits.One);
port.Open();
ASCIIEncoding ascii = new ASCIIEncoding();
port.Write(ascii.GetString(new byte[] { 28, 112, 1, 0})); //Printing the Above uploaded Logo
port.WriteLine("Your Text");
port.Close();
}
--
或另外的方法:
public string GetLogo()
{
string logo = "";
if (!File.Exists(@"C:\bitmap.bmp"))
return null;
BitmapData data = GetBitmapData(@"C:\bitmap.bmp");
BitArray dots = data.Dots;
byte[] width = BitConverter.GetBytes(data.Width);
int offset = 0;
MemoryStream stream = new MemoryStream();
BinaryWriter bw = new BinaryWriter(stream);
bw.Write((char)0x1B);
bw.Write('@');
bw.Write((char)0x1B);
bw.Write('3');
bw.Write((byte)24);
while (offset < data.Height)
{
bw.Write((char)0x1B);
bw.Write('*'); // bit-image mode
bw.Write((byte)33); // 24-dot double-density
bw.Write(width[0]); // width low byte
bw.Write(width[1]); // width high byte
for (int x = 0; x < data.Width; ++x)
{
for (int k = 0; k < 3; ++k)
{
byte slice = 0;
for (int b = 0; b < 8; ++b)
{
int y = (((offset / 8) + k) * 8) + b;
// Calculate the location of the pixel we want in the bit array.
// It'll be at (y * width) + x.
int i = (y * data.Width) + x;
// If the image is shorter than 24 dots, pad with zero.
bool v = false;
if (i < dots.Length)
{
v = dots[i];
}
slice |= (byte)((v ? 1 : 0) << (7 - b));
}
bw.Write(slice);
}
}
offset += 24;
bw.Write((char)0x0A);
}
// Restore the line spacing to the default of 30 dots.
bw.Write((char)0x1B);
bw.Write('3');
bw.Write((byte)30);
bw.Flush();
byte[] bytes = stream.ToArray();
return logo + Encoding.Default.GetString(bytes);
}
public BitmapData GetBitmapData(string bmpFileName)
{
using (var bitmap = (Bitmap)Bitmap.FromFile(bmpFileName))
{
var threshold = 127;
var index = 0;
double multiplier = 570; // this depends on your printer model. for Beiyang you should use 1000
double scale = (double)(multiplier/(double)bitmap.Width);
int xheight = (int)(bitmap.Height * scale);
int xwidth = (int)(bitmap.Width * scale);
var dimensions = xwidth * xheight;
var dots = new BitArray(dimensions);
for (var y = 0; y < xheight; y++)
{
for (var x = 0; x < xwidth; x++)
{
var _x = (int)(x / scale);
var _y = (int)(y / scale);
var color = bitmap.GetPixel(_x, _y);
var luminance = (int)(color.R * 0.3 + color.G * 0.59 + color.B * 0.11);
dots[index] = (luminance < threshold);
index++;
}
}
return new BitmapData()
{
Dots = dots,
Height = (int)(bitmap.Height*scale),
Width = (int)(bitmap.Width*scale)
};
}
}
public class BitmapData
{
public BitArray Dots
{
get;
set;
}
public int Height
{
get;
set;
}
public int Width
{
get;
set;
}
}
--抓英文或數字(過濾中文和符號)
Select * From [TableName] Where [ColumnName1] Not Like '%[^A-Za-z0-9]%'
其實單就這方面看起來,就淺顯易懂了
[^A-Za-z0-9] <==這部分就是所謂的不等於A-Za-z0-9的字元
此時再加個Not就是所謂的"不等於的不等於" 就是代表資料只能有A-Za-z0-9的字元
'建立XML
Imports System.Xml
'建立XML
Private Sub CreateXML()
Dim xdoc As XmlDocument
Dim xElement As XmlElement
Dim xChildElement As XmlElement
Dim xElement2 As XmlElement
Dim xChildElement2 As XmlElement
Try
'建立一個 XmlDocument 物件並加入 Declaration
xdoc = New XmlDocument
xdoc.AppendChild(xdoc.CreateXmlDeclaration("1.0", "UTF-8", "yes"))
'建立根節點物件並加入 XmlDocument 中 (第0層)
xElement = xdoc.CreateElement("sections")
'在sections寫入一個屬性
xElement.SetAttribute("data_name", "部門人員資訊")
xdoc.AppendChild(xElement)
'在sections下寫入一個節點名稱為section(第1層)
xChildElement = xdoc.CreateElement("section")
xChildElement.SetAttribute("department", "人資部")
xChildElement.SetAttribute("department_code", "2200")
xElement.AppendChild(xChildElement)
'第2層節點
xElement2 = xdoc.CreateElement("users")
xChildElement.AppendChild(xElement2)
'第3層節點
xChildElement2 = xdoc.CreateElement("user")
xChildElement2.SetAttribute("Name", "孫小美")
xChildElement2.SetAttribute("Year", "16")
xChildElement2.SetAttribute("Sex", "女")
xElement2.AppendChild(xChildElement2)
'在sections下寫入一個節點名稱為section(第1層)
xChildElement = xdoc.CreateElement("section")
xChildElement.SetAttribute("department", "資訊部")
xChildElement.SetAttribute("department_code", "3100")
xElement.AppendChild(xChildElement)
'第2層節點
xElement2 = xdoc.CreateElement("users")
xChildElement.AppendChild(xElement2)
'第3層節點
xChildElement2 = xdoc.CreateElement("user")
xChildElement2.SetAttribute("Name", "張寶成")
xChildElement2.SetAttribute("Year", "23")
xChildElement2.SetAttribute("Sex", "男")
xElement2.AppendChild(xChildElement2)
xChildElement2 = xdoc.CreateElement("user")
xChildElement2.SetAttribute("Name", "蕭瀟瀟")
xChildElement2.SetAttribute("Year", "26")
xChildElement2.SetAttribute("Sex", "男")
xElement2.AppendChild(xChildElement2)
xdoc.Save("C:\Users\Desktop\XML_Create.xml")
Catch ex As Exception
MessageBox.Show(ex.Message & System.Environment.NewLine & ex.StackTrace)
End Try
End Sub
其中XML的內容在生成後長成這樣
==================================================
<?xml version="1.0"encoding="UTF-8"standalone="yes"?>
<sections data_name="部門人員資訊">
<section department="人資部"department_code="2200">
<users>
<user Name="孫小美" Year="16"Sex="女" />
</users>
</section>
<section department="資訊部"department_code="3100">
<users>
<user Name="張寶成"Year="23"Sex="男" />
<user Name="蕭瀟瀟"Year="26"Sex="男" />
</users>
</section>
</sections>
==================================================
'讀取XML
Private Sub LoadXML()
Dim xdoc As XmlDocument = New XmlDocument
Dim xRoot As XmlNode
Dim xNodeList As XmlNodeList
Dim xNodeTemp As XmlNode
Dim xUsersNode As XmlNode
Dim xUserNodeList As XmlNodeList
Dim xUserNode As XmlNode
Dim xElement As XmlElement
Try
'讀取XML
xdoc.Load("C:\Users\Desktop\XML_Create.xml")
xRoot = CType(xdoc.DocumentElement, XmlNode)
'選擇section
xNodeList = xRoot.SelectNodes("section[@department!='' and @department_code='3100']")
For intI As Integer = 0 To xNodeList.Count - 1
xNodeTemp = xNodeList.Item(intI)
'取得節點[users]
xUsersNode = xNodeTemp.SelectSingleNode("users")
'取得[user]Name有值的節點
xUserNodeList = xUsersNode.SelectNodes("user[@Name!='']")
For intJ As Integer = 0 To xUserNodeList.Count - 1
xUserNode = xUserNodeList.Item(intJ)
xElement = CType(xUserNode, XmlElement)
Console.Write("姓名:" & xElement.GetAttribute("Name"))
Console.WriteLine()
Console.Write("年齡:" & xElement.GetAttribute("Year"))
Console.WriteLine()
Console.Write("性別:" & xElement.GetAttribute("Sex"))
Console.WriteLine()
Next
Next
Catch ex As Exception
MessageBox.Show(ex.Message & System.Environment.NewLine & ex.StackTrace)
End Try
End Sub