做一个简单的短语背诵程序
首先得有一个数据库
英文短语和中文一一对应
看看过程
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“englishDataSet.sentence”中。您可以根据需要移动或移除它。
this.sentenceTableAdapter.Fill(this.englishDataSet.sentence);
this.DesktopLocation = new Point(450, 0); //设置窗口在频目的位置
DataTable dt = new DataTable();
Random rm = new Random();
int i = rm.Next(1, 400);
dt = sentenceTableAdapter.GetDataByid(i);
label1.Text = dt.Rows[0][1].ToString();
label2.Text = dt.Rows[0][2].ToString();
}
private void label1_Click(object sender, EventArgs e)
{
//单击Label1的时候也从数据库中 随机出一个短语
DataTable dt = new DataTable();
Random rm = new Random();
int i = rm.Next(1, 400);
dt = sentenceTableAdapter.GetDataByid(i);
label1.Text = dt.Rows[0][1].ToString();
label2.Text = dt.Rows[0][2].ToString();
}
private void Form1_MouseDown_1(object sender, MouseEventArgs e)
{
//使用API函数 来拽动 窗口
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
private void label2_Click(object sender, EventArgs e)
{
//单击Label2的时候也从数据库中 随机出一个短语
DataTable dt = new DataTable();
Random rm = new Random();
int i = rm.Next(1, 400);
dt = sentenceTableAdapter.GetDataByid(i);
label1.Text = dt.Rows[0][1].ToString();
label2.Text = dt.Rows[0][2].ToString();
}
private void timer1_Tick(object sender, EventArgs e)
{
//每过30秒换一个 短语
DataTable dt = new DataTable();
Random rm = new Random();
int i = rm.Next(1, 400);
dt = sentenceTableAdapter.GetDataByid(i);
label1.Text = dt.Rows[0][1].ToString();
label2.Text = dt.Rows[0][2].ToString();
}
}
}
一个比较简单的应用
全当自己练练手吧
有一个问题 就是我想让窗体自定义到最小 不能实现
高手帮忙下啊
怎么调整 窗体的大小 使用哪个属性