using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using UserShareNet; namespace demo_CSharp04 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // enable timer1 timer1.Interval = 250; // 250 ms timer1.Enabled = true; } private void timer1_Tick(object sender, EventArgs e) { byte[] msg = new byte[255]; string tmp_str; // Get string value UserShare.Get_STRING(Convert.ToUInt16(1), msg); tmp_str = byte_array_tounicode(msg); string_val.Text = tmp_str; // Get string value UserShare.Get_STRING(Convert.ToUInt16(2), msg); tmp_str = byte_array_tounicode(msg); string_val2.Text = tmp_str; // Get string value UserShare.Get_STRING(Convert.ToUInt16(3), msg); tmp_str = byte_array_tounicode(msg); string_val3.Text = tmp_str; } private void Button_string_Click(object sender, EventArgs e) { byte[] msg; msg = unicode_to_byte_array(new_string_val.Text); UserShare.Set_STRING((UInt16)1, msg); } private void Button_string2_Click(object sender, EventArgs e) { byte[] msg; msg = unicode_to_byte_array(new_string_val2.Text); UserShare.Set_STRING((UInt16)2, msg); } private void Button_string3_Click(object sender, EventArgs e) { byte[] msg; msg = unicode_to_byte_array(new_string_val3.Text); UserShare.Set_STRING((UInt16)3, msg); } private string byte_array_tounicode(byte[] buf) { string tmpmsg; if (buf.Length > 255) return null; tmpmsg = Encoding.GetEncoding("UTF-8").GetString(buf, 0, buf.Length); return tmpmsg; } private byte[] unicode_to_byte_array(string msg) { byte[] tmpbuf; if (msg.Length > 255) return null; tmpbuf = Encoding.GetEncoding("UTF-8").GetBytes(msg); return tmpbuf; } } }