public void SetFont() { string AppPath = Application.StartupPath; try { PrivateFontCollection font = new PrivateFontCollection(); font.AddFontFile(AppPath + @"\font\JOKERMAN.TTF");//字体的路径及名字 font.AddFontFile(AppPath + @"\font\造字工房映力黑规体.otf"); Font jokermanFont22 = new Font(font.Families[0], 22F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0))); Font titleFont12 = new Font(font.Families[1], 12F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134))); Font titleFont10 = new Font(font.Families[1], 10F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0))); //设置窗体控件字体,哪些控件要更改都写到下面 label1.Font = titleFont12; label2.Font = titleFont12; label3.Font = jokermanFont22; button6.Font = titleFont12; button1.Font = titleFont10; } catch { using (Form_Tips tip = new Form_Tips("警告", "字体不存在或加载失败\n程序将以默认字体显示")) { tip.ShowDialog(); } } }
private async void AddTravel(string title, int uid) { Travel travel = new Travel(); XmlSerializer xmlSerializer = new XmlSerializer(typeof(Travel)); Client client = new Client(); string data = ""; try { string url = "https://localhost:5001/api/Travel"; travel.Description = title; travel.Uid = uid; using (StringWriter sw = new StringWriter()) { xmlSerializer.Serialize(sw, travel); data = sw.ToString(); } HttpResponseMessage result = await client.Post(url, data); if (result.IsSuccessStatusCode) { using (Form_Tips tip = new Form_Tips("提示", "成功创建")) { tip.ShowDialog(); } init(); } else { using (Form_Tips tip = new Form_Tips("警告", result.StatusCode.ToString())) { tip.ShowDialog(); } } } catch (Exception e1) { using (Form_Tips tip = new Form_Tips("警告", e1.Message)) { tip.ShowDialog(); } } }
private async void button6_Click(object sender, EventArgs e) { string userID = textBox1.Text; string password = textBox2.Text; string passwordMD5 = MD5Encrypt(password); if (userID.Length == 0 || userID == "单行输入") { DialogResult result; using (Form_Tips tip = new Form_Tips("提示", "用户ID为空,是否注册新账号")) { tip.ShowDialog(); result = tip.DialogResult; } if (result == DialogResult.Yes) { using (Form_Register reg = new Form_Register()) { this.Hide(); reg.ShowDialog(); this.Show(); } } } else { if (password.Length == 0 || password == "单行输入") { using (Form_Tips tip = new Form_Tips("提示", "请输入密码!")) { tip.ShowDialog(); } } else { try { string url = baseUrl + "/login?Uid=" + userID + "&password="******""); if (result.IsSuccessStatusCode) { using (Form_TripNote tn = new Form_TripNote(int.Parse(userID))) { tn.changePanel = tn.AddControlsToPanel; this.Hide(); tn.ShowDialog(); textBox1.Text = ""; textBox2.Text = ""; } this.Show(); } else { using (Form_Tips tip = new Form_Tips("警告", "用户名或密码输入错误")) { tip.ShowDialog(); } } } catch (Exception e1) { using (Form_Tips tip = new Form_Tips("警告", e1.Message)) { tip.ShowDialog(); } } } } }
private async void button6_Click(object sender, EventArgs e) { if (Txtbox_name.Text.Length == 0 || Txtbox_name.Text == "单行输入") { using (Form_Tips tip = new Form_Tips("提示", "请输入用户名!")) { tip.ShowDialog(); } } else if (TxtBox_psw.Text.Length == 0 || TxtBox_psw.Text == "单行输入") { using (Form_Tips tip = new Form_Tips("提示", "请输入密码!")) { tip.ShowDialog(); } } else { User user = new User(); XmlSerializer xmlSerializer = new XmlSerializer(typeof(User)); Client client = new Client(); string data = ""; try { string url = baseUrl + "/register"; user.Uname = Txtbox_name.Text; user.Password = MD5Encrypt(TxtBox_psw.Text); user.Sex = Cbbox_gender.Text; user.Introduction = richTextBox_introducation.Text; using (StringWriter sw = new StringWriter()) { xmlSerializer.Serialize(sw, user); data = sw.ToString(); } HttpResponseMessage result = await client.Post(url, data); if (result.IsSuccessStatusCode) { User newuser = new User(); newuser = (User)xmlSerializer.Deserialize(await result.Content.ReadAsStreamAsync()); user.Uid = int.Parse(newuser.Uid.ToString("00000")); using (Form_Tips tip = new Form_Tips("提示", "注册成功!您的ID是" + newuser.Uid.ToString("00000"))) { tip.ShowDialog(); } using (Form_TripNote tn = new Form_TripNote()) { this.Hide(); tn.ShowDialog(); this.Dispose(); } } } catch (Exception e1) { using (Form_Tips tip = new Form_Tips("警告", e1.Message)) { tip.ShowDialog(); } } } }