winforms,charts,onclick,position,coordinates , Windows Forms Chart: Get mouse cursor coordinates in Chart axis scale?


Windows Forms Chart: Get mouse cursor coordinates in Chart axis scale?

Question:

Tag: winforms,charts,onclick,position,coordinates

I have a problem with the following sample:

enter image description here

When I click at the place marked as '1' on my screenshot, I can get position in pixels by MouseClick event in a pretty easy way:

private: System::Void chart1_MouseClick(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {

        Point chartLocationOnForm = chart1->FindForm()->PointToClient(chart1->Parent->PointToScreen(chart1->Location));                

        cursorPosX = e->X - chartLocationOnForm.X;
        cursorPosY =  e->Y - chartLocationOnForm.Y;
}

After printing these values out, I get the position in pixels, where position marked as '2' is equal to (0,0).

What I would like to get after clicking the spot in '1' is

X: 40
Y: 178.5
,

which are the coordinates inside my chart. Is there any civilised way to do that (I mean other than considering padding, margins and borders of the chart and calculating these coordinates by myself)?

One of my ideas was to create some sort of invisible CursorX and CursorY and use its methods, but it still seems to be more like a fancy way to solve simple problem than a real, straight-forward solution. Am I right or this really is the way I am supposed to solve my problem?


Answer:

Yep, there is a civilized way of doing that if I understand your question correctly. You can use the Axis.PixelPositionToValue method to do just that.

E.g. (in C#)

chart.ChartAreas[0].AxisX.PixelPositionToValue(pt.X)
chart.ChartAreas[0].AxisY.PixelPositionToValue(pt.Y)

Related:


Properly display list of custom objects in Windows Forms' Property Grid


c#,winforms,propertygrid,typeconverter
I'm trying to display the properties of my Wall class in a properties grid. Right now my wall class looks like this: [TypeConverter(typeof(ExpandableObjectConverter))] public class WallType { #region _private variables and Properties public string Name { get; set; } //Name of the wall to identify it. For the wall program,...

google charts change background color


charts,background,google-visualization,background-color
I saw some previous questions/answers here on StackOverflow but none of the code provided in those answers seemed to work with my chart: Here is my code: <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("visualization", "1.1", {packages:["bar"]}); google.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ ['Month', 'Sales', 'Expenses'], ['January', 200, 150], ['February',...

Custom Numericupdown


c#,winforms,custom-controls
I'm trying to create a custom numericUpDown control. I'm trying to add text to the numericUpDown and I got it working good. But, now I want to find a way to select only the number when clicking in the control, because at this moment when I "edit" the value manually,...

Why i'm getting exception StackOverFlowException ? And how to solve it?


c#,.net,winforms
I added a new form in form1 i have a button click event: private void button1_Click(object sender, EventArgs e) { UploadTestingForum utf = new UploadTestingForum(); utf.Show(); } And the new form code i took from example here: https://github.com/youtube/api-samples/blob/master/dotnet/UploadVideo.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq;...

C# Windows Form Application - value not printing in textbox for each time


c#,winforms,textbox,windows-forms-designer,form-control
Value not printing in textbox for each time.. Iam able to see last value only (10) in textbox. private void button1_Click(object sender, EventArgs e) { for(int i = 0; i<=10; i++) { textBox1.Text = i.ToString(); Thread.Sleep(100); } } ...

Updating a list of objects bound to a DataGridView from a popup form


c#,winforms,datagridview
I seem to be having a bit of a problem with returning the updated information on my edit button placed on the popup form, back to my DataGridView (which is bound to a list of objects) on the original form. I seemed to have it working the other day, however,...

Angular nvd3 MultiChart X Axis Calibration issue with dual Y Axis


javascript,angularjs,charts,nvd3.js
I am working on a solution where I may need to plot multiple series in a single chart to show an analysis on the given data. Therefore, I have used Angular nvd3 multiChart to display multiple bar charts based on right-Y axis, while the other chart based on left-Y axis....

How to get the range of a specific word in Word Document using Word Interop


c#,winforms,ms-word,word-interop
I am creating a C# program that inserts a table inside a word document. Now, I need to insert a table in a certain position in different word documents. All word documents/templates I have has the word <table> in it where I want to insert the table. For me to...

WPF: after add WPF Toolkit DLL


wpf,charts,wpftoolkit
After add rrr DLL i am looking at this tutorial. Do i need to add some reference in my XAML in order to find chartingToolkit:Chart ?

Why does this code to replace accented chars with html codes fail to work?


c#,html,winforms,diacritics,accented-strings
I want to replace accented chars (such as á, ñ, ¿, ¡, etc.) with the corresponding HTML codes (such as á, ñ, ¿, ¡, etc.). For example, this line of text: Imposible me ha sido rehusarme á las repetidas instancias que el Caballero Trelawney, el Doctor Livesey y otros muchos...

Getting Multi Rows in Database and transferring it in a multiline textbox in VB.net WinForms


database,vb.net,winforms,textbox
Here in my code, i have a database which has table of my applicants. As you will see in the code below, i want to get the number of rows from my command text and transfer it to the string "abc" Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As...

Set Label From Thread


vb.net,multithreading,winforms
Form1.vb Imports System.Threading Public Class Form1 Dim demoThread As Thread Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim Start As New Class1 Me.demoThread = New Thread( _ New ThreadStart(AddressOf Start.ThreadProcSafe)) Me.demoThread.Start() End Sub Delegate Sub SetTextCallback([text] As String) Public Sub SetText(ByVal [text] As String) ' InvokeRequired required...

How do I prevent any button click events from queuing until the event handle is finished with the first call


c#,winforms,event-handling
I want to prevent a button click from queuing. In testing I have a Form, a Button and in the Code-Behind I have the event handler: private void button1_Click(object sender, EventArgs e) { if (_codeRunning) return; _codeRunning = true; //Application.DoEvents(); //button1.Enabled = false; _click ++; Debug.WriteLine("Click Number: " + _click);...

How do I display an Icon on the Taskbar but not on the form itself?


vb.net,winforms,visual-studio
If I use ShowIcon in the form properties, I get the icon in the top left of my form (I don't want that), but I do get my icon in the taskbar. If I turn ShowIcon off, then I get no icon on the form but I get the default...

How do I keep previously painted objects from disappearing when a new one is creating in a Windows Form Application?


c#,winforms
My problem is that within my Windows Form Application, I want to draw an Ellipse everytime the mouse is clicked within a specific picture box, and I want the previously drawn ellipses to remain present in the picture box. In its current state, once the mouse is clicked, the previously...

How to make inherited form full screen [on hold]


c#,winforms
I am having some trouble trying to get a windows form project go full screen and to hide the taskbar. I am inheriting forms from a master form. When I add the following code it still shows the task bar at the bottom. this.TopMost = true; this.FormBorderStyle = FormBorderStyle.None; this.WindowState...

Form controls not showing


c#,forms,winforms,user-interface,user-controls
I'm making a console application that shows a form. I created the form from scratch. When I run the program, the form shows, but the controls I added don't show. My code: using System; using System.Windows.Forms; using System.Drawing; namespace form { public class main { public static void Main() {...

Adding data to DBF file adds column _NullFlags


c#,winforms,oledb,dbf
Im currently working on a program that gets information from a sql database and creates a .DBF that has the information in there. I got it to the point where it makes the file and adds the columns/rows. But every time I run it, it adds a column named _NullFlags...

How to make if statement that checks if multple listBoxes are empty or not?


c#,winforms,if-statement,listbox
How do I make an if statement that asks if multiple listBoxes are empty or not? This is what I have so far...is it possible to combine it into one single if statement? if (listBoxEmails.Items.Count < 1) { //Perform action } if (listBoxWebsites.Items.Count < 1) { //Perform action } if...

Move windows form from a picturebox in C#


c#,.net,winforms,picturebox
I have a windows form without any border. So i added a picture box and i want the whole form to be moved when that picture box is clicked. public const int WM_NCLBUTTONDOWN = 0xA1; public const int HT_CAPTION = 0x2; [DllImportAttribute("user32.dll")] public static extern int SendMessage(IntPtr hWnd, int Msg,...

Load all user controls of a form on start


c#,winforms,events,user-controls
My Winform application has a main form with a tab control. In each tab there is a User Control. And each user control has Controls (such as DataGridViews, etc) that are loaded on the Load event of the user control. The problem I have is that I would like to...

Issue with int numbers using chart.js


javascript,charts,charts.js
So, I'm exploring this code: http://jsfiddle.net/UNs9J/5611/ $(function(){ $("#doughnutChart").drawDoughnutChart([ { title: "Tokyo", value : 120, color: "#2C3E50" }, { title: "San Francisco", value: 80, color: "#FC4349" }, { title: "New York", value: 70, color: "#6DBCDB" }, { title: "London", value : 50, color: "#F7E248" }, { title: "Sydney", value : 40,...

Check whether print command success or not


c#,.net,winforms,printing
I am printing some PDF files through c# code. My code looks like this myPrinters.SetDefaultPrinter(pdfPrinterName); var info = new ProcessStartInfo { Verb = "Print", FileName = file, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden }; var p = new Process { StartInfo = info }; p.Start(); p.WaitForInputIdle(); System.Threading.Thread.Sleep(18000); if (!p.CloseMainWindow()) p.Kill();...

Application is missing required files


c#,.net,windows,winforms,sharpdevelop
Pic of Error: http://s23.postimg.org/7uj6qcxtn/9708083373e57a9ec91e4296e302f88e.png Cannot Download the Application. The Application is missing required Files. Contact Application Vendor For Assistance. So I'm building a windows form application using SharpDevelop 5.2 and I'm trying to make a standalone/version someone else would be able to use on another machine. In sharpdevelop (and visual...

D3.js Enter, Update, Exit issue


javascript,d3.js,charts,updates
I have a relatively simple barchart. I want to .transition() between datasets with an .on("click") event. What I'm getting is a complete redraw of an additional chart appended to the DOM id, instead of removing the original chart and transitioning or replacing it. I think I'm misunderstanding how to correctly...

Is it possible to login from a winforms application to a website which uses spring security?


java,c#,winforms,spring-mvc,spring-security
I want to call a web service from my winforms application. My application is written on c# and the webservice is secured using spring security. Is it possible to login to the website and call that web service?. If it is possible how to do that?...

How can i put formclosing event in Button


c#,winforms
i make this button btnCallenge and i want if the person click on it the form can't be closed if he try to close it i want the form cant be closed if the user click on chellange button public void btnChallenge_Click(object sender, EventArgs e) { } private void Form1_FormClosing(object...

getting keyboard input in winform listbox


c#,winforms,keyevent
i am altering a program so that a listbox picks up keyboard input (number pad, D0-D9, letter keys) and edits properties of the currently selected listbox item based on the input. my problem is that there seems to be no functionality that can convert a key press into a letter....

Managing per form ObjectContext lifetime


c#,winforms,entity-framework,orm
For ORMs like EF and NHibernate, multiple places suggest using "context per method" (or per request, per transaction) for web apps and services and using "context per form" for thick clients like WinForms and WPF. In C#, resource disposal with context per method is clean and clear with a using...

DialogBox with value verifications


c#,.net,winforms
For my application which deals with graphics, I've made a little DialogBox to set: Max; Min; Major Step (of the scale); Minor Step. Here's a screen capture: I want to validate a few things before allowing the user to click Ok: Max >= Min MaxScale >= MinScale. But it's not...

How can i get list of my youtube videos from youtube?


c#,.net,winforms,youtube,youtube-api
I installed the google api 3 and the OAuth2. And i tried the google develope example: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Google.GData.Client; using Google.GData.Extensions; using Google.GData.YouTube; using Google.GData.Extensions.MediaRss; using Google.YouTube; namespace Youtube_Manager { public partial class...

How to change background Color of label full length when Mouse Hover in c#


c#,winforms
I can't Select label back Ground color Mouse Hover event in full length,only can select The Word length I would like to get log out background same like username background as full width private void label5_MouseHover(object sender, EventArgs e) { this.LblChange.BackgroundImage = null; this.LblChange.BackgroundImage = global::Flex.Properties.Resources.Mail1; this.LblChange.BackColor = Color.Blue; this.LblChange.BackgroundImageLayout...

Dynamically Resizing Controls on Windows Forms


c#,winforms,layout
I has a winform which can be resize. I has 4 chart control in the form and sit side by side. When the form is in maximum size, the layout of each chart control is run out. I try to set the anchor style but i got no luck. How...

SaveFileDialog not displaying


c#,.net,winforms
EDITED CODE/QUESTION. BEGININVOKE IS NOT LONGER ON THE TABLE. I'm having trouble getting a SaveFileDialog to show its dialog. When I call ShowDialog normally I get no response at all. The code falls through and acts like the SFD was never called in the first place. I also tried running...

Improve DataGridView rows managing


.net,vb.net,winforms,datagridview,datatable
SCENARIO I'm manually filling a DataGridView with a DataGridViewRow collection: I created the columns at design time in the GUI builder of Visual Studio. First column takes an Integer value, its a DataGridViewTextBoxColumn. Second column takes an Icon object, its a DataGridViewImageColumn. Third column takes a String value, its...

Chart JavaFX, my hover Label are hidden by the edges of chart


charts,javafx,popup,linechart
I have a problem again with the JavaFX Chart : D Context : I had Popup/Label on my chart to display the value on hover : JavaFX LineChart Hover Values (Jewelsea answer) Problem : But when the point are near the edges of chart, the popup is hidden by them....

Value cannot be null when deserializing JSON


c#,winforms,json.net
I have a db table which has column in which content is stored in JSON format, I am retrieving JSON but I am getting this error. Value cannot be null Here is my code snippet. var stuff = (JObject)JsonConvert.DeserializeObject(commentId); string name = stuff["Name"].Value<string>(); string email = stuff["Email"].Value<string>(); string company =...

Google charts different colors w/ single series Material bar chart


charts,google-visualization
Using {role: 'style'} I can apply different colors to a single series bar chart. But if I use the new Google "Material" barcharts, I can't. "regular" Google charts (works): google.load("visualization", '1.1', {packages:['corechart']}); google.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ ['Element', 'Density', {role: 'style'} ], ['Copper', 8.94, 'color: #FF9900'], ['Silver',...

Responsive axis with percentage coordinates


javascript,svg,d3.js,graph,charts
In an attempt to build a responsive scatter graph with d3.js, I'm using %-based coordinates in a 100% x 100% svg element. How can I .call(axis) and get it to layout the axis using % and not px values, so that they always fit the svg and the plotted data?...

DataGridView KeyDown manipulation (enter, left, right, etc.) not working when multiselect


c#,winforms,datagridview,multi-select
I want to make the DataGridView more handy while manipulating the KeyDown event, like the KeyEnter for moving one cell to the right, or using left, down or up. I have some special use cases where I want to check first the cell and depending on that I can discard...

MVP in WinForms ( presenter & program.cs)


c#,winforms,mvp
I'm learning an MVP pattern and have the following issues: If I have one form(project MainForm), one model(project Model) and one presenter, should I create a new project for my presenter or it's ok to put it in MainForm project? 1)If presenter must be located in separate project, it obviously...

Custom drawing using System.Windows.Forms.BorderStyle?


c#,.net,vb.net,winforms,custom-controls
I want to mimick drawing of default border based on value of property BorderStyle. Instead of single border around the control, my control is visualised as four adjacent custom-drawn boxes (2×2), each having standard border drawn individually. So for example, if Control.Border is set to FixedSingle value I want to...

Unable to bind data to DataGridView by using BindingList in WinForm application


c#,excel,winforms,datagridview
I am reading data from excel file (.csv) and storing that data to List<String>. I want to display this data to DataGridView but for some reason I am seeing total length of String in Grid. Following is my code : CODE: private void btnImportFile_Click(object sender, EventArgs e) { OpenFileDialog dialog...

Copying CMD output to clipboard


c#,winforms,cmd
I'm trying to copy output from a program running out of the CMD prompt to the Windows clipboard. private void button1_Click(object sender, EventArgs e) { /*Relevant Code*/ Process p = new Process(); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.FileName = "cmd.exe"; p.StartInfo.Arguments = String.Format("/k cd {0} && backdoor -rt -on...

How to use XDocument to get attributes and add them to a List


c#,xml,winforms,list
I am trying to load data from an XML file and add it to a List. The XML file looks like this: and this is my code: public void LoadPayments(List<List<string>> list1, List<List<string>> list2) { try { if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RentData.xml"))) { int count = 0; XDocument doc; using (var reader =...

Why when adding items to combobox it's adding the same item many times?


c#,.net,winforms
In the top of form1: public class ComboboxItem { public string Text { get; set; } public object Value { get; set; } public override string ToString() { return Text; } } List<string> results = new List<string>(); Then: ComboboxItem item = new ComboboxItem(); var result = videoCatagories.Execute(); for (int i...

Notify winforms application by Sql Server database changes


c#,.net,sql-server,winforms,sqldependency
I created a Sql server database, in which I added a table named user. Then I executed this script ALTER DATABASE [TestNotification] SET ENABLE_BROKER I'd like to use SqlDependency class to notify a winforms application when the user table were changed. namespace Watcher { public partial class Form1 : Form...

Spline chart drawn on the xaxis in case of single value or constant values - highchart


javascript,html,charts,highcharts
while using the older version of highchart - 2.1.6, if a plot had only one value or a series of same values, it would plot at the middle of the screen as below. But, ever since i have upgraded the version of the highchart to 4.1.5, the line sticks to...

How to change the colour and style of MajorGrid of AxisY in ASP.net chart


c#,asp.net,charts
I made a chart in asp.net and I want to change the color of the MajorGrid to light grey and style to dash. Any suggestions?

How to create a folder that contains the current date and time instead of name


winforms,visual-studio-2013,c++-cli
I use C++ Windows Form application in Visual Studio 2013 for one project. I wonder how to create a folder that contains the current date and time instead of name? It is possible to make such folder?? DirectoryInfo^ directory = Directory::CreateDirectory("C:\Users\Desktop\" + ??); ...