本文介绍了获取一类对象C#从鼠标悬停值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个360号码一个txt文件,我必须阅读所有这些,并绘制了一种作出的灰阶彩色FillPie eachone的光盘由于列表的价值。直到这里的一切是相当simple.I做了一个类(在TXT和度值)单一fillpie的与绘制正确颜色的漆方法中的数据。 ,这是类的代码: 类DatoDisco { INT valoreSpicchio; INT gradi; 公共DatoDisco(INT valoreTastatore,诠释gradiLettura) { valoreSpicchio = valoreTastatore; gradi = gradiLettura; } 公共无效清除() { valoreSpicchio = 0; gradi = 0; } 私人诠释ScalaGrigi() { INT皮诺= 0; 如果(valoreSpicchio< = 0) {皮诺= 125 +(valoreSpicchio / 10); 如果(皮诺℃,)皮诺= 0; } 如果(valoreSpicchio大于0) {皮诺= 125 +(valoreSpicchio / 10); 如果(皮诺> 230)皮诺= 230; } 返回皮诺; } 公共无效涂料(图形画报) {试 {刷宾纳=新SolidBrush(Color.FromArgb(255 ,ScalaGrigi(),ScalaGrigi(),ScalaGrigi())); grafica.FillPie(彭纳,0,0,400,400,gradi,1.0F); } 抓 {} } 公众诠释ValoreSpicchio {的get {返回valoreSpicchio; } } 公众诠释Gradi {得到 {返回gradi; } } } 这里是我画的一切 公共部分类萨马茨:表 { libnodave.daveOSserialType FDS; libnodave.daveInterface迪; libnodave.daveConnection直流电; INT机架= 0; INT插槽= 2; INT scalaGrigi = 0; INT angolatura = 0; 名单,LT; INT> valoriY =新的List< INT>(); //迪斯科舞厅=新开的迪厅(); 名单,LT; D​​atoDisco>迪斯科=新的List< D​​atoDisco>(); 浮法[] = valoriTastatore新的浮动[360]; 公共马茨() {的InitializeComponent(); StreamReader的数据流=新的StreamReader(save.txt的); textBox1.Text = dataStream.ReadLine(); dataStream.Dispose(); 的for(int i = 0; I< = 360;我++) chart1.Series [系列2] Points.Add(0); //AggiornaGrafico(textBox1.Text,chart1); 的SetStyle(ControlStyles.SupportsTransparentBackColor,真); } 串indirizzoIpPlc {得到 { FileIniDataParser分析器=新FileIniDataParser(); IniData设置= parser.LoadFile(config.ini文件); 返回设置[PLC_CONNECTION] [PLC_IP]; } } 私人无效AggiornaGrafico(字符串nomeFile,图画报,布尔在线) { INT最大值= 0; INT分钟= 0; grafico.Series [系列1] Points.Clear()。 grafico.Series [系列2] Points.Clear()。 grafico.Series [系列3] Points.Clear()。 grafico.Series [系列4] Points.Clear()。 grafico.ChartAreas [0] .AxisX.Maximum = 360; grafico.ChartAreas [0] .AxisX.Minimum = 0; grafico.ChartAreas [0] .AxisY.Maximum = 500; grafico.ChartAreas [0] = .AxisY.Minimum -500; 字符串文件= nomeFile; valoriY.Clear(); disco.Clear(); 如果(在线==假) { System.IO.File.WriteAllText(save.txt的nomeFile); } StreamReader的dataStreamGrafico =新的StreamReader(文件); StreamReader的dataStreamScheda =新的StreamReader(Scheda.sch); 串datasample; 的String [] = scheda新的字符串[56]; 的for(int i = 0; I< 56;我++) { scheda [I] = dataStreamScheda.ReadLine(); } dataStreamScheda.Close(); INT gradi = 1; ,而((datasample = dataStreamGrafico.ReadLine())!= NULL) { grafico.Series [系列2] Points.Add(0); grafico.Series [系列2]颜色= Color.Red。 grafico.Series [系列2] =边框宽度3。 grafico.Series [系列3] Points.Add(Convert.ToInt32(float.Parse(scheda [5]))); grafico.Series [系列3]颜色= Color.Green。 grafico.Series [系列3] =边框宽度3。 grafico.Series [系列4] Points.Add(Convert.ToInt32(-float.Parse(scheda [5]))); grafico.Series [系列4]颜色= Color.Green。 grafico.Series [系列4] =边框宽度3。 grafico.Series [系列1] Points.Add(int.Parse(datasample))。 grafico.Series [系列1] =边框宽度5。 valoriY.Add(int.Parse(datasample)); //disco.Add(int.Parse(datasample)); disco.Add(新DatoDisco(int.Parse(datasample),gradi)); gradi ++; } dataStreamGrafico.Close(); 最大= Convert.ToInt32(chart1.Series [系列1] Points.FindMaxByValue()YValues​​ [0]); 分钟= Convert.ToInt32(chart1.Series [系列1] Points.FindMinByValue()YValues​​ [0]); lblCampanatura.Text =(((浮动)+最大分钟)/ 2000.0)的ToString(); lblSbandieramento.Text =(((浮点)最大值 - 最小值)/ 1000.0)的ToString(); 如果((Math.Abs​​(最大值)> 800)||(Math.Abs​​(分钟)GT 800)) {如果(Math.Abs​​(最大)> = Math.Abs​​(分钟)) { chart1.ChartAreas [0] = .AxisY.Maximum MAX + 200; chart1.ChartAreas [0] .AxisY.Minimum = - (最大值+ 200); } ,否则 { chart1.ChartAreas [0] = .AxisY.Maximum MIN + 200; chart1.ChartAreas [0] .AxisY.Minimum = - (分钟+ 200); } } ,否则 { chart1.ChartAreas [0] .AxisY.Maximum = 800; chart1.ChartAreas [0] = .AxisY.Minimum -800; } boxGraficaDisco.Refresh(); } 私人无效的button1_Click(对象发件人,EventArgs五) { DialogResult的结果= openFileDialog1.ShowDialog(); textBox1.Text = openFileDialog1.FileName; 如果(结果== DialogResult.OK) { AggiornaGrafico(textBox1.Text,chart1,timer1.Enabled); } } 工具提示工具提示=新工具提示(); 私人诠释lastX; 私人诠释lastY; 私人无效chart1_MouseMove(对象发件人,MouseEventArgs E) {如果(前!= this.lastX || EY!= this.lastY) {试 { INT cursorX = Convert.ToInt32(chart1.ChartAreas [0] .AxisX.PixelPositionToValue(e.Location.X)); tooltip.Show(X:+ cursorX.ToString(0.00)+Y:+ Convert.ToInt32(chart1.Series [0] .Points [cursorX] .YValues​​ [0 ])的ToString(),this.chart1,e.Location.X + 20,e.Location.Y + 20); } 赶上{} } this.lastX = e.X; this.lastY = e.Y; } 私人无效button1_Click_1(对象发件人,EventArgs五) { INT指数之=((int)的Char.GetNumericValue(textBox1.Text [textBox1.Text 。长度 - 5]))+ 1; 如果(File.Exists(textBox1.Text.Substring(0,textBox1.Text.Length - 5)+指数之+名.txt)) { textBox1.Text = textBox1的。 Text.Substring(0,textBox1.Text.Length - 5)+指数之+.TXT; 试 { AggiornaGrafico(textBox1.Text,chart1,timer1.Enabled); } 抓 { MessageBox.Show(金日成文件不esiste); } } ,否则 { MessageBox.Show(金日成文件不esiste); } } 私人无效btnGrafMeno_Click(对象发件人,EventArgs五) { INT指数之=((int)的Char.GetNumericValue(textBox1的。文本[textBox1.Text.Length - 5])) - 1; 如果(指数之> = 0) { textBox1.Text = textBox1.Text.Substring(0,textBox1.Text.Length - 5)+指数之+名.txt; 试 { AggiornaGrafico(textBox1.Text,chart1,timer1.Enabled); } 抓 { MessageBox.Show(金日成文件不esiste); } } ,否则 { MessageBox.Show(厦华lettura迪斯科); } } 私人无效btnConnetti_Click(对象发件人,EventArgs五) { fds.rfd = libnodave.openSocket(102 indirizzoIpPlc); fds.wfd = fds.rfd; 如果(fds.rfd大于0) {二=新libnodave.daveInterface(FDS,IF1,0,libnodave.daveProtoISOTCP,libnodave.daveSpeed​​187k); di.setTimeout(1000000); 直流=新libnodave.daveConnection(DI,0,机架,槽); INT解析度= dc.connectPLC(); timer1.Start(); // AggiornaGrafico(Disco.csv,chart1,timer1.Enabled); } ,否则 { MessageBox.Show(Impossibile connettersi); } } 私人无效timer1_Tick(对象发件人,EventArgs五) {如果(timer1.Enabled ==真) {中期业绩; 解析度= dc.readBytes(libnodave.daveDB,21,40,1,NULL); 如果(RES == 0) {变种letturaDati =(dc.getS8At(0)及(1 { INT puntatore = 30; 的StreamWriter datiDisco =新的StreamWriter(DatiDaPlc.csv); datiDisco.WriteLine(X;+C:+Z;); ,而(puntatore< = 10838) {解析度= dc.readBytes(libnodave.daveDB,3,puntatore,192,NULL); 如果(RES == 0) {的for(int i = 0; dc.getU32At(我)!= 0; i = i + 12) { datiDisco.Write(dc.getU32At(ⅰ)的ToString()+;); datiDisco.Write(dc.getU32At第(i + 4)的ToString()+;); datiDisco.WriteLine(dc.getFloatAt第(i + 8)的ToString()+;); } } puntatore = puntatore + 192; } datiDisco.Close(); StreamReader的lettura =新的StreamReader(DatiDaPlc.csv); 的StreamWriter scritt =新的StreamWriter(Disco.csv); VAR TITOLO = lettura.ReadLine(); VAR posizioneLettura = lettura.ReadLine(); VAR POSX = posizioneLettura.Split(';'); INT其minX = Convert.ToInt32(POSX [0]) - 5; INT MAXX = Convert.ToInt32(POSX [0])+ 5; INT contatore = 0; (!lettura.EndOfStream),而 {无功行= lettura.ReadLine(); VAR值= line.Split(';'); 如果((Convert.ToInt32(值[1])> = contatore&放大器;&放大器; Convert.ToInt32(值[1])&下; contatore + 1000)及及(转换。 ToInt32(值[0])>其minX&放大器;&放大器; Convert.ToInt32(值[0])&下; = MAXX)) { scritt.WriteLine(Convert.ToInt32(float.Parse(值[2])* 1000)的ToString()); contatore + = 1000; } } lettura.Close(); scritt.Close(); AggiornaGrafico(Disco.csv,chart1,timer1.Enabled); } } ,否则 { timer1.Stop(); MessageBox.Show(Disconnesso); dc.disconnectPLC(); di.disconnectAdapter(); fds.rfd = libnodave.closeSocket(102); fds.wfd = fds.rfd; } } } 私人无效btnDisconnetti_Click(对象发件人,EventArgs五) {如果(timer1.Enabled ==真) { dc.disconnectPLC(); di.disconnectAdapter(); fds.rfd = libnodave.closeSocket(102); fds.wfd = fds.rfd; timer1.Stop(); AggiornaGrafico(textBox1.Text,chart1,timer1.Enabled); } } 私人无效Samac_FormClosing(对象发件人,FormClosingEventArgs E) {如果(timer1.Enabled ==真) { dc.disconnectPLC(); di.disconnectAdapter(); libnodave.closeSocket(102); timer1.Stop(); } } 私人无效button1_Click_2(对象发件人,EventArgs五) {如果(timer1.Enabled ==真) { AggiornaGrafico(Disco.csv,chart1,timer1.Enabled); } ,否则 { AggiornaGrafico(textBox1.Text,chart1,timer1.Enabled); } } 私人无效chart2_MouseMove(对象发件人,MouseEventArgs E) {如果(前!= this.lastX || EY!= this.lastY) {试 { INT cursorX = Convert.ToInt32(chart2.ChartAreas [0] .AxisX.PixelPositionToValue(e.Location.X)); INT走马= Convert.ToInt32(chart2.ChartAreas [0] .AxisY.PixelPositionToValue(e.Location.Y)); //tool​​tip.Show(\"X:+ chart2.Series [0] .Points [cursorX] .XValue.ToString()+Y:+ chart2.Series [0] .Points [cursorX]。 YValues​​ [0]的ToString(),this.chart2,e.Location.X + 20,e.Location.Y + 20); tooltip.Show(X:+ cursorX.ToString()+Y:#VALY,this.chart2,e.Location.X + 20,e.Location.Y + 20); //chart2.Series[0].ToolTip=\"#VALY } 赶上{} } this.lastX = e.X; this.lastY = e.Y; } 私人无效boxGraficaDisco_Paint(对象发件人,PaintEventArgs的E) {图形画报= e.Graphics; //disco.Paint(grafica); 的foreach(在迪斯科DatoDisco D) { d.Paint(画报); } } 私人无效boxGraficaDisco_MouseMove(对象发件人,MouseEventArgs E) {如果(前!= this.lastX || EY!= this.lastY) {试 {的foreach(DatoDisco d在迪斯科) { } $} b $ b赶上{} } this.lastX =; 6。 this.lastY = e.Y; } } 现在我需要的,当我去的鼠标拉制盘,工具提示告诉我fillPie(度和TXT值)的数据,但我无法弄清楚如何。 任何人都可以帮我吗? ,这是盘 的图像解决方案 最后,它看起来好像你想要的是一个函数来获取鼠标位置和光盘。 $ b $的中心之间的角度b 下面是计算给出了两个百分点角度的功能: 双AngleFromPoints(点PT1,点PT2) {点P =新的点(pt1.X - pt2.X,pt1.Y - pt2.Y); 双阿尔法= 0D; 如果(P.Y == 0)阿尔法= P.X> 0? 0D:180D; ,否则 {双F = 1D * P.X /(的Math.sqrt(P.X * P.X + P.Y * P.Y)); 阿尔法= Math.Acos(F)* 180D / Math.PI; 如果(P.Y大于0)阿尔法= 360D - α; } 阿尔法回报; } I've a txt file with a 360 numbers, I must read all of these and draw a kind of Disc made of FillPie eachone colored in scale of grey due to the value of the list. Until here everything is quite simple.I made a class with the data(value in the txt and degree) of one single fillpie with a Paint method that draw it of the correct color.this is the code of the class:class DatoDisco{ int valoreSpicchio; int gradi; public DatoDisco(int valoreTastatore, int gradiLettura) { valoreSpicchio = valoreTastatore; gradi = gradiLettura; } public void Clear() { valoreSpicchio = 0; gradi = 0; } private int ScalaGrigi() { int grigio = 0; if (valoreSpicchio <= 0) { grigio = 125 + (valoreSpicchio / 10); if (grigio < 0) grigio = 0; } if (valoreSpicchio > 0) { grigio = 125 + (valoreSpicchio / 10); if (grigio > 230) grigio = 230; } return grigio; } public void Paint (Graphics grafica) { try { Brush penna = new SolidBrush(Color.FromArgb(255, ScalaGrigi(), ScalaGrigi(), ScalaGrigi())); grafica.FillPie(penna, 0, 0, 400, 400, gradi, 1.0f); } catch { } } public int ValoreSpicchio { get { return valoreSpicchio; } } public int Gradi { get { return gradi; } } }here is where I draw everything:public partial class Samac : Form{ libnodave.daveOSserialType fds; libnodave.daveInterface di; libnodave.daveConnection dc; int rack = 0; int slot = 2; int scalaGrigi = 0; int angolatura = 0; List<int> valoriY = new List<int>(); //Disco disco = new Disco(); List<DatoDisco> disco = new List<DatoDisco>(); float[] valoriTastatore = new float[360]; public Samac() { InitializeComponent(); StreamReader dataStream = new StreamReader("save.txt"); textBox1.Text = dataStream.ReadLine(); dataStream.Dispose(); for (int i = 0; i <= 360; i++ ) chart1.Series["Series2"].Points.Add(0); //AggiornaGrafico(textBox1.Text, chart1); SetStyle(ControlStyles.SupportsTransparentBackColor, true); } string indirizzoIpPlc { get { FileIniDataParser parser = new FileIniDataParser(); IniData settings = parser.LoadFile("config.ini"); return settings["PLC_CONNECTION"]["PLC_IP"]; } } private void AggiornaGrafico(string nomeFile, Chart grafico, bool online) { int max = 0; int min = 0; grafico.Series["Series1"].Points.Clear(); grafico.Series["Series2"].Points.Clear(); grafico.Series["Series3"].Points.Clear(); grafico.Series["Series4"].Points.Clear(); grafico.ChartAreas[0].AxisX.Maximum = 360; grafico.ChartAreas[0].AxisX.Minimum = 0; grafico.ChartAreas[0].AxisY.Maximum = 500; grafico.ChartAreas[0].AxisY.Minimum = -500; String file = nomeFile; valoriY.Clear(); disco.Clear(); if (online == false) { System.IO.File.WriteAllText("save.txt", nomeFile); } StreamReader dataStreamGrafico = new StreamReader(file); StreamReader dataStreamScheda = new StreamReader("Scheda.sch"); string datasample; string[] scheda = new string[56]; for (int i = 0; i < 56; i++) { scheda[i] = dataStreamScheda.ReadLine(); } dataStreamScheda.Close(); int gradi = 1; while ((datasample = dataStreamGrafico.ReadLine()) != null) { grafico.Series["Series2"].Points.Add(0); grafico.Series["Series2"].Color = Color.Red; grafico.Series["Series2"].BorderWidth = 3; grafico.Series["Series3"].Points.Add(Convert.ToInt32(float.Parse(scheda[5]))); grafico.Series["Series3"].Color = Color.Green; grafico.Series["Series3"].BorderWidth = 3; grafico.Series["Series4"].Points.Add(Convert.ToInt32(-float.Parse(scheda[5]))); grafico.Series["Series4"].Color = Color.Green; grafico.Series["Series4"].BorderWidth = 3; grafico.Series["Series1"].Points.Add(int.Parse(datasample)); grafico.Series["Series1"].BorderWidth = 5; valoriY.Add(int.Parse(datasample)); //disco.Add(int.Parse(datasample)); disco.Add(new DatoDisco(int.Parse(datasample), gradi)); gradi++; } dataStreamGrafico.Close(); max = Convert.ToInt32(chart1.Series["Series1"].Points.FindMaxByValue().YValues[0]); min = Convert.ToInt32(chart1.Series["Series1"].Points.FindMinByValue().YValues[0]); lblCampanatura.Text = (((float)max + min) / 2000.0).ToString(); lblSbandieramento.Text = (((float)max - min) / 1000.0).ToString(); if ((Math.Abs(max) > 800) || (Math.Abs(min) > 800)) { if (Math.Abs(max) >= Math.Abs(min)) { chart1.ChartAreas[0].AxisY.Maximum = max + 200; chart1.ChartAreas[0].AxisY.Minimum = -(max + 200); } else { chart1.ChartAreas[0].AxisY.Maximum = min + 200; chart1.ChartAreas[0].AxisY.Minimum = -(min + 200); } } else { chart1.ChartAreas[0].AxisY.Maximum = 800; chart1.ChartAreas[0].AxisY.Minimum = -800; } boxGraficaDisco.Refresh(); } private void button1_Click(object sender, EventArgs e) { DialogResult result = openFileDialog1.ShowDialog(); textBox1.Text = openFileDialog1.FileName; if (result == DialogResult.OK) { AggiornaGrafico(textBox1.Text, chart1, timer1.Enabled); } } ToolTip tooltip = new ToolTip(); private int lastX; private int lastY; private void chart1_MouseMove(object sender, MouseEventArgs e) { if (e.X != this.lastX || e.Y != this.lastY) { try { int cursorX = Convert.ToInt32(chart1.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X)); tooltip.Show("X:" + cursorX.ToString("0.00") + "Y:" + Convert.ToInt32(chart1.Series[0].Points[cursorX].YValues[0]).ToString(), this.chart1, e.Location.X + 20, e.Location.Y + 20); } catch { } } this.lastX = e.X; this.lastY = e.Y; } private void button1_Click_1(object sender, EventArgs e) { int indice = ((int)Char.GetNumericValue(textBox1.Text[textBox1.Text.Length - 5]))+1; if (File.Exists(textBox1.Text.Substring(0, textBox1.Text.Length - 5) + indice + ".txt")) { textBox1.Text = textBox1.Text.Substring(0, textBox1.Text.Length - 5) + indice + ".txt"; try { AggiornaGrafico(textBox1.Text, chart1, timer1.Enabled); } catch { MessageBox.Show("Il File non esiste"); } } else { MessageBox.Show("Il File non esiste"); } } private void btnGrafMeno_Click(object sender, EventArgs e) { int indice = ((int)Char.GetNumericValue(textBox1.Text[textBox1.Text.Length - 5])) - 1; if (indice >= 0) { textBox1.Text = textBox1.Text.Substring(0, textBox1.Text.Length - 5) + indice + ".txt"; try { AggiornaGrafico(textBox1.Text, chart1, timer1.Enabled); } catch { MessageBox.Show("Il File non esiste"); } } else { MessageBox.Show("Prima lettura disco"); } } private void btnConnetti_Click(object sender, EventArgs e) { fds.rfd = libnodave.openSocket(102, indirizzoIpPlc); fds.wfd = fds.rfd; if (fds.rfd > 0) { di = new libnodave.daveInterface(fds, "IF1", 0, libnodave.daveProtoISOTCP, libnodave.daveSpeed187k); di.setTimeout(1000000); dc = new libnodave.daveConnection(di, 0, rack, slot); int res = dc.connectPLC(); timer1.Start(); // AggiornaGrafico("Disco.csv", chart1, timer1.Enabled); } else { MessageBox.Show("Impossibile connettersi"); } } private void timer1_Tick(object sender, EventArgs e) { if (timer1.Enabled == true) { int res; res = dc.readBytes(libnodave.daveDB, 21, 40, 1, null); if (res == 0) { var letturaDati = (dc.getS8At(0) & (1 << 0)) != 0; if (letturaDati == true) { int puntatore = 30; StreamWriter datiDisco = new StreamWriter("DatiDaPlc.csv"); datiDisco.WriteLine("X;" + "C;" + "Z;"); while (puntatore <= 10838) { res = dc.readBytes(libnodave.daveDB, 3, puntatore, 192, null); if (res == 0) { for (int i = 0; dc.getU32At(i) != 0; i = i + 12) { datiDisco.Write(dc.getU32At(i).ToString() + ";"); datiDisco.Write(dc.getU32At(i + 4).ToString() + ";"); datiDisco.WriteLine(dc.getFloatAt(i + 8).ToString() + ";"); } } puntatore = puntatore + 192; } datiDisco.Close(); StreamReader lettura = new StreamReader("DatiDaPlc.csv"); StreamWriter scritt = new StreamWriter("Disco.csv"); var titolo = lettura.ReadLine(); var posizioneLettura = lettura.ReadLine(); var posX = posizioneLettura.Split(';'); int minX = Convert.ToInt32(posX[0]) - 5; int maxX = Convert.ToInt32(posX[0]) + 5; int contatore = 0; while (!lettura.EndOfStream) { var line = lettura.ReadLine(); var values = line.Split(';'); if ((Convert.ToInt32(values[1]) >= contatore && Convert.ToInt32(values[1]) < contatore + 1000) && (Convert.ToInt32(values[0]) > minX && Convert.ToInt32(values[0]) <= maxX)) { scritt.WriteLine(Convert.ToInt32(float.Parse(values[2]) * 1000).ToString()); contatore += 1000; } } lettura.Close(); scritt.Close(); AggiornaGrafico("Disco.csv", chart1, timer1.Enabled); } } else { timer1.Stop(); MessageBox.Show("Disconnesso"); dc.disconnectPLC(); di.disconnectAdapter(); fds.rfd = libnodave.closeSocket(102); fds.wfd = fds.rfd; } } } private void btnDisconnetti_Click(object sender, EventArgs e) { if (timer1.Enabled == true) { dc.disconnectPLC(); di.disconnectAdapter(); fds.rfd = libnodave.closeSocket(102); fds.wfd = fds.rfd; timer1.Stop(); AggiornaGrafico(textBox1.Text, chart1, timer1.Enabled); } } private void Samac_FormClosing(object sender, FormClosingEventArgs e) { if (timer1.Enabled == true) { dc.disconnectPLC(); di.disconnectAdapter(); libnodave.closeSocket(102); timer1.Stop(); } } private void button1_Click_2(object sender, EventArgs e) { if (timer1.Enabled == true) { AggiornaGrafico("Disco.csv", chart1, timer1.Enabled); } else { AggiornaGrafico(textBox1.Text, chart1, timer1.Enabled); } } private void chart2_MouseMove(object sender, MouseEventArgs e) { if (e.X != this.lastX || e.Y != this.lastY) { try { int cursorX = Convert.ToInt32(chart2.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X)); int cursorY = Convert.ToInt32(chart2.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y)); //tooltip.Show("X:" + chart2.Series[0].Points[cursorX].XValue.ToString() + "Y:" + chart2.Series[0].Points[cursorX].YValues[0].ToString(), this.chart2, e.Location.X + 20, e.Location.Y + 20); tooltip.Show("X:" + cursorX.ToString() + "Y:#VALY" , this.chart2, e.Location.X + 20, e.Location.Y + 20); //chart2.Series[0].ToolTip="#VALY"; } catch { } } this.lastX = e.X; this.lastY = e.Y; } private void boxGraficaDisco_Paint(object sender, PaintEventArgs e) { Graphics grafica = e.Graphics; //disco.Paint(grafica); foreach (DatoDisco d in disco) { d.Paint(grafica); } } private void boxGraficaDisco_MouseMove(object sender, MouseEventArgs e) { if (e.X != this.lastX || e.Y != this.lastY) { try { foreach (DatoDisco d in disco) { } } catch { } } this.lastX = e.X; this.lastY = e.Y; }}Now I need that when i go with the mouse over the drawn disc, a tooltip show me the data of the fillPie(degree and value of txt) but i can't figure out how.Anyone can help me?this is an image of the disc 解决方案 Eventually it looks as if all you want is a function to get the angle between the mouse position and the center of the disc..Here is a function to calculate an angle given two points:double AngleFromPoints(Point pt1, Point pt2){ Point P = new Point(pt1.X - pt2.X, pt1.Y - pt2.Y); double alpha = 0d; if (P.Y == 0) alpha = P.X > 0 ? 0d : 180d; else { double f = 1d * P.X / (Math.Sqrt(P.X * P.X + P.Y * P.Y)); alpha = Math.Acos(f) * 180d / Math.PI; if (P.Y > 0) alpha = 360d - alpha; } return alpha;} 这篇关于获取一类对象C#从鼠标悬停值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 16:16