沒看懂题,说错了,不好意思
你可以用API函數做..這是我剛做的一個,你看看.CODE如下:
[DllImport("user32.dll")]
static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("user32.dll")]
static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc);
[DllImport("gdi32.dll")]
static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos);
static public System.Drawing.Color GetPixelColor(int x, int y)
{
IntPtr hdc = GetDC(IntPtr.Zero);
uint pixel = GetPixel(hdc, x, y);
ReleaseDC(IntPtr.Zero, hdc);
Color color = Color.FromArgb((int)(pixel & 0x000000FF),
(int)(pixel & 0x0000FF00) >> 8,
(int)(pixel & 0x00FF0000) >> 16);
return color;
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
textBox1.Text = e.X.ToString();//坐標x值
textBox2.Text = e.Y.ToString();//坐標y值
richTextBox1.Text=GetPixelColor(e.X, e.Y).ToString();
textBox3.Text = checkcolor(richTextBox1.Text.Trim(),"R=");//R值
textBox4.Text = checkcolor(richTextBox1.Text.Trim(), "G=");//G值
textBox5.Text = checkcolor(richTextBox1.Text.Trim(), "B=");//B值
richTextBox1.Text = "該點的像數值是: R=" + textBox3.Text.Trim() + " G=" + textBox4.Text.Trim() + " B=" + textBox5.Text.Trim();
}
private string checkcolor(string temp,string filed)
{
string b = string.Empty;
if (filed == "R=")
{
b = temp.Trim().Substring(temp.Trim().IndexOf(filed) + filed.Length, temp.Trim().IndexOf("G=") - (temp.Trim().IndexOf(filed) + filed.Length+2));
}
if (filed == "G=")
{
b = temp.Trim().Substring(temp.Trim().IndexOf(filed) + filed.Length, temp.Trim().IndexOf("B=") - (temp.Trim().IndexOf(filed) + filed.Length+2));
}
if (filed == "B=")
{
b = temp.Substring(temp.IndexOf(filed) + filed.Length, temp.Length - (temp.IndexOf(filed) + filed.Length+1));
}
return b;
}
[[it] 本帖最后由 wzg0319 于 2008-8-18 10:51 编辑 [/it]]