Click here to Skip to main content
       

Windows Forms

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page  Show 
AdminForum Guidelines - PLEASE READadminChris Maunder28-Jul-09 2:38 
When posting your question please:
  1. Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
     
  2. Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
     
  3. Keep the subject line brief, but descriptive. eg "File Serialization problem"
     
  4. Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
     
  5. Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
     
  6. Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
     
  7. If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
     
  8. Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
     
  9. Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
     
  10. Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
     
  11. If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
     
  12. No advertising or soliciting.
     
  13. We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
 
When answering a question please:
  1. Read the question carefully
     
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
     
  3. If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
     
  4. If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
 
cheers,
Chris Maunder
 
The Code Project Co-founder
Microsoft C++ MVP

QuestionMessage Automatically Removedgroupzhangjinfu29-May-13 15:45 
Message Automatically Removed
QuestionListBox does not update when DataSource is changedmemberrbsbscrp17-May-13 5:36 
Well, I'm plum out of ideas. I've got a listbox with a List<> for its DataSource. When I init it - before the form is displayed, it works. But not after that. I am modifying the List<> contents and then I run:
 
public void RefreshLbx()
{
    lbxQuotes.DataSource = null;
    lbxQuotes.DataSource = _quotes;
}
 
where _quotes is the List<>
 
Now here is where it gets weird. I put a button on the form - here's its handler:
 
private void btnRefresh_Click(object sender, EventArgs e)
{
    RefreshLbx();
}
 
So that when I click on the button then the lbxQuotes listbox is properly updated. But in the modification code - where I call RefreshLbx() directly, nothing happens.
 
I even tried invoking btnRefresh_Click() in the code, but alas could not find the magic.
 
Oh one other thought - the modification code is in a timer event handler - could this be a problem of trying to modify a control from a different thread? All I am doing is changing the List<> contents and then reseting the DataSource.
 
I must be missing something to kick the listbox to redisplay, or something... HELP!
AnswerRe: ListBox does not update when DataSource is changedmemberrbsbscrp17-May-13 6:59 
Wow but this is weird. Okay, I found the solution because I tried the recommendation given below:
 
lbxQuotes.DataSource = null;
lbxQuotes.DataSource = _quotes;
lbxQuotes.SelectionMode = SelectionMode.None;
lbxQuotes.SelectionMode = SelectionMode.One;
 
That is, I added the SelectionMode two lines... and this caused (only once) a "from different thread" exception. Weird, I'm NOT running a method - I'm changing data... hmmm... I wonder if the DataSource is instead a Property (which secretly runs a method). D'oh!
 
Okay, so the solution was to create a delegate in the main form, for the RefreshLbx method, and have the RefreshLbx method recursively call this, as below:
 
public void RefreshLbx()
{
    if (lbxQuotes.InvokeRequired)
    {
        lbxQuotes.Invoke(_refreshLbx);
    }
    else
    {
        lbxQuotes.DataSource = null;
        lbxQuotes.DataSource = _quotes;
    }
}
 
with the _refreshLbx delegate defined in the form's class as:
 
private delegate void RefreshLbxDg8();
private RefreshLbxDg8 _refreshLbx;
 
Then just init the delegate in the form constructor (after the InitializeComponent() call):
 
        _refreshLbx = RefreshLbx;
 
Now I am able to update the listbox contents from a timer handler.
GeneralRe: ListBox does not update when DataSource is changedmvpEddy Vluggen24-May-13 2:59 
"System.Threading.Timer" is not threadsafe. You didn't use the Timer from the Toolbox, did you?
 
rbsbscrp wrote:
Weird, I'm NOT running a method - I'm changing data... hmmm...
You're changing a property from a different thread than where the control was created.
 
rbsbscrp wrote:
if the DataSource is instead a Property (which secretly runs a method).
Yup, it's a property; meaning it's built from two methods (not threads!)
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]

GeneralRe: ListBox does not update when DataSource is changedmvpDave Kreskowiak24-May-13 5:23 
You can NOT so much as touch ANY part of a control from a thread other than the one that created it, the UI (or startup) thread. This is where your entire problem comes from.
 
You have to Invoke methods on the UI thread that manipulates the control for your calling code.

GeneralRe: ListBox does not update when DataSource is changedmemberrbsbscrp24-May-13 20:03 
My thanks to all who responded.
 
>>
You can NOT so much as touch ANY part of a control from a thread other than the one that created it, the UI (or startup) thread. This is where your entire problem comes from.
 
My confusion was mostly that I was not trying to run a Method at all - I was just changing a Property (or what I thought was DATA). Upon more consideration, I realized that a Property is just syntactic sugar over a procedure call, anyway, so the "you can't run code from a different thread" rule applied even changing a Property.
 
However, I am mystified as to WHY this rule "no touchie from different thread" even exists. Sure, if I'm trying to update a TextBox from other threads then there *could* be confusion and a random mix of characters added from the various threads due to the asynchronous timing of the code in the different threads. Yes, there *could* be... it is *possible* - just like I could really mess up a data structure if I update it from many threads without synchronization.
 
But that is exactly what multithreaded coding is all about - synchronizing the use of common data structures (at least it is a major issue, if not the biggest issue).
 
But why would the compiler assume that I am needing multithreading synchronization when updating a Textbox? The truth is, I am doing something at timed intervals - I am using a timer. It just so *happens* that C# chooses internally to implement a timer via a separate new thread. That is not *my* problem. I'm not trying to append text to the textbox from 17 different timers or asynchronous threads. I'm simply trying to update a textbox at constant intervals - in this case the system chooses to do this via ONE (other) thread.
 
Suddenly now I have to become fully knowledgeable about multithreading and delegates and "invoking", etc. BAH! Unnecessary, unneeded, unwanted complexification.
 
Aside from all that, I especially did not appreciate that the code simply failed to do anything - I got no compiler warning/error nor any runtime problem. My dialogbox simply didn't update. Then I had the fire up The Google and go searching for why it didn't work. My first real clue was that if I caused the update to happen from the very same function, via a click of a button on the UI, then it worked. Whaaa? My code definitely worked, but only if executed via a pushbutton.
 
I've coded for years, and I'm teaching myself C# now, and "yeah" this is a noobie kinda problem, but geeeez what an unnecessary timewaster.
 
Okay, 'nuff whining. Thx to all who replied. I found some code example for doing a "invoke" via a deleagate, etc., etc., and got it working.
GeneralRe: ListBox does not update when DataSource is changedmvpEddy Vluggen24-May-13 23:03 
rbsbscrp wrote:
It just so *happens* that C# chooses internally to implement a timer via a separate new thread.
The timer from the toolbox doesn't; it's simply a component that raises an event at a specified interval.
 
rbsbscrp wrote:
That is not *my* problem.
True - you're simply using the wrong timer-control. (Yes, there's more than one)
 
rbsbscrp wrote:
I found some code example for doing a "invoke" via a deleagate, etc., etc., and got it working.
Thumbs Up | :thumbsup:
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]

GeneralRe: ListBox does not update when DataSource is changedmvpDave Kreskowiak25-May-13 3:55 
Wow! You have such a myopic view of what's going on.
 
The reason you need Invoke is because controls are NOT thread safe. What you see in the toolbox are .NET wrappers around standard window variants you find in Win32. They are not thread safe because of limitations in the Windows user interface. The golden rule is that any operation on a control is required to be done by the thread that created the window handle. It's possible to wrap all this code in synchronzation code, but that would have been a ton of code and a rather large performance hit.
 
But, but, but "I'm just changing a property!" Yeah, I know. A property is nothing but a method that gets/sets a value, but that method can also do other things like validation, modifying other values inside the control, updating the controls internal state machine, kicking off events, and whatever else the controls need.
 
What you're forgetting is that Windows is a shared system. Not only can your code cause code in the contorl to run, but Windows can too, AT ANY TIME. It can send your control a WM_PAINT message to get your control to repaint itself, but, what if you were changing the Text or Forecolor properties, from your thread, at the exact same time the control was getting these values to use in the paint code??
 
Invoke is there because .NET, like any other application, has to follow the "UI thread rule" like any other application.
 
A little tidbit: The only methods on controls that ARE thread safe are Invoke, BeginInvoke, EndInvoke and CreateGraphics.

GeneralRe: ListBox does not update when DataSource is changedmemberrbsbscrp30-May-13 14:16 
Wow! You have such a myopic view of what's going on.
 
I don't think so. Let's revisit this one more time.
 
So I'm supposed to put all code that modifies a control into wrapper code that calls invoke and this wrapper code ends up being a conditional test to see if invoke is required and then recursively calling the same function thru a special delegate that is created just for that invoke call. I've repeated my example code below:
 
private delegate void RefreshLbxDg8();
private RefreshLbxDg8 _refreshLbx;
...
_refreshLbx = RefreshLbx;
...
public void RefreshLbx()
{
    if (lbxQuotes.InvokeRequired)
    {
        lbxQuotes.Invoke(_refreshLbx);
    }
    else
    {
        lbxQuotes.DataSource = null;
        lbxQuotes.DataSource = _quotes;
    }
}
 
All this is required in order that the code gets executed on the GUI thread. Now, I'm simply updating a textbox with a sample (number). Nothing else.
 
I guess I could have stated my point better: yes, it is an asynchronous system and it is *possible* that a WM_PAINT would get processed while the textbox text is changing. I am aware of this. My complaint was that .NET designers used this sledgehammer solution to prevent any presentation rendering mishap (ie. my number is rendered while it is changing) by constraining all code to execute on the GUI thread. So this means that for every single interaction with any control - and there's a LOT of them, I'm supposed to write wrapper code around everything, and this wrapper code involves defining and creating delegates and rewriting all my code to include a conditional statement which tests for this invokability.
 
AND YOU'RE FINE WITH THIS.
 
Me, I think this is a horrible and terribly primitive solution and design. It would be better to leave me with using SendMessage() to inject my action into the GUI's Message-Loop.
 
And that's not to mention that the compiler gave no warnings, there was no runtime error, the code SILENTLY failed, and I had no idea that the timer implemented its actions with a (hidden) separate thread.
 
I am LESS than impressed.
GeneralRe: ListBox does not update when DataSource is changedmvpDave Kreskowiak30-May-13 16:19 
Liek I said, it's a limitation in Windows Win32 since the dark arges, not .NET.
 
If this bugs the crap out of you, go write code for Linux.

GeneralRe: ListBox does not update when DataSource is changedmemberrbsbscrp30-May-13 17:38 
A SendMessage() call works between threads... at least I thought it did. Thus I thought this was a .NET constraint.
 
If it's not a .NET new constraint then I just learned something.
 

Dave Kreskowiak wrote:
go write code for Linux.

 
No! (so there)
GeneralRe: ListBox does not update when DataSource is changedmvpDave Kreskowiak31-May-13 4:25 
rbsbscrp wrote:
No! (so there)

 
Then quit bitching...

GeneralRe: ListBox does not update when DataSource is changedmemberrbsbscrp31-May-13 5:41 
Dave Kreskowiak wrote:
Then quit bitching...

 
Your discourse is not civil, but constant.
GeneralRe: ListBox does not update when DataSource is changedmvpEddy Vluggen31-May-13 6:29 
Let it go. It's like looking at a game who will have the last word on a subject.
 
FWIW; Linux/Mono would react exactly the same.
GeneralRe: ListBox does not update when DataSource is changedmvpEddy Vluggen31-May-13 6:27 
rbsbscrp wrote:
Me, I think this is a horrible and terribly primitive solution and design.
Microsoft had the same idea; that's why the threaded version of the timer isn't in the WinForms designer-toolbox. The Timer from the toolbox simply raises events on the GUI-thread. No syncing required.
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]

GeneralRe: ListBox does not update when DataSource is changedmemberrbsbscrp31-May-13 7:22 
Hmmmmm... I am using a System.Windows.Forms.Timer. Isn't that the one you are referring to that doesn't use a separate thread? Okay, now I'm confused. My code works if i execute it from a button. It works if I invoke it thru a delegate. Other than that nothing happens.
GeneralRe: ListBox does not update when DataSource is changedmvpEddy Vluggen31-May-13 7:30 
Let me add to the confusion; there's not two, but three[^] timers available.
 
So, which timer is it? Smile | :)
 
..and there's a picture in that article of a second timer in the toolbox. Nice to see my previous post invalidated that quickly.
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]

GeneralRe: ListBox does not update when DataSource is changedmemberrbsbscrp31-May-13 7:39 
Wow, wonderful article.
 
Again, the timer that I'm using is the System.Windows.Forms.Timer one (I'm cut&pasting this from the .Designer.cs file - and I don't see any other timers)
 
Thx for the article. I'll look at all this in a bit.
GeneralRe: ListBox does not update when DataSource is changedmvpEddy Vluggen31-May-13 8:32 
rbsbscrp wrote:
the timer that I'm using is the System.Windows.Forms.Timer one
That one runs on the UI thread, and doesn't need any invocations to update controls created.
using System;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Thread.CurrentThread.Name = "UI Thread";
        }
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            Text = String.Format("{0}, {1}", Thread.CurrentThread.Name, Environment.TickCount);
            // Thread.Sleep(1000); Try resizing after uncommenting this
        }
    }
}
The timer is based on the Windows message-pump;
// System.Windows.Forms.Timer.TimerNativeWindow
protected override void WndProc(ref Message m)
{
	if (m.Msg == 275)
	{
		if ((int)m.WParam == this._timerID)
		{
			this._owner.OnTick(EventArgs.Empty);
			return;
		}
	}
	else
	{
		if (m.Msg == 16)
		{
			this.StopTimer(true, m.HWnd);
			return;
		}
	}
	base.WndProc(ref m);
}
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]

GeneralRe: ListBox does not update when DataSource is changedmemberTnTinMn6-Jun-13 9:08 
I know that this is a bit late, but have you ever considered using the BindingList(Of T) Class[^] instead? It will notify any changes to the list so that the bound control can take action.
GeneralRe: ListBox does not update when DataSource is changedmemberrbsbscrp6-Jun-13 12:38 
I'm not familiar with BindingList. I took a quick look at the link but am unsure of its benefit here. Thx for the heads up, though.
GeneralRe: ListBox does not update when DataSource is changedmemberTnTinMn6-Jun-13 13:26 
Perhaps I misunderstood your problem, I thought that it was that the ListBox was not automatically reflecting changes to the underlying DataSource List. The BindingList raises events that would cause the ListBox to update automatically when the List changes.
 
Here is a simple example. New WinForm project with two buttons and two ListBoxes. Clicking Button1 adds items to the underlying lists, but only the ListBox with the BindingList as the DataSource is update. Clicking Button2 tells ListBox1 to Refresh it's data.
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;
 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        List<int> L1 = new List<int>();
        BindingList<int> L2 = new BindingList<int>();
        private void Form1_Load(object sender, EventArgs e)
        {
            L1.Add(1);
            L1.Add(2);
            L2.Add(11);
            L2.Add(22);
            listBox1.DataSource = L1;
            listBox2.DataSource = L2;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            this.button2.Click += new System.EventHandler(this.button2_Click);
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            L1.Add(3);  // adds a value to L1, but listBox1 does not display it until the binding is refresshed
            L2.Add(33); // adds a value to L2 and listBox2 is automatically refreshed to display it
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            // tell listBox1 to refresh the data
            ((CurrencyManager)this.BindingContext[L1]).Refresh();
        }
    }
}

AnswerRe: ListBox does not update when DataSource is changedmemberChirag Baroliya R24-May-13 2:25 
Try This :
 
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
List<KeyValuePair<int, string>> data = new List<KeyValuePair<int, string>>();
 
KeyValuePair<int, string> item;
 
for (int i = 1; i < 10; i++)
{
item = new KeyValuePair<int, string>(i, "Item " + i.ToString());
data.Add(item);
 
}
 
listBox1.DataSource = data;
listBox1.DisplayMember = "Value";
listBox1.ValueMember = "Key";
 
}
 
private void button1_Click(object sender, EventArgs e)
{
KeyValuePair<int, string> item = new KeyValuePair<int,string>(11,"Item 11");
 
List<KeyValuePair<int, string>> data = (List<KeyValuePair<int, string>>)listBox1.DataSource;
data.Add(item);
 
listBox1.DataSource = null;
listBox1.DataSource = data;
 
}
}
GeneralRe: ListBox does not update when DataSource is changedmemberrbsbscrp24-May-13 20:11 
Kuel. I like that you can use a List<> of Key/Values for a ListBox. Did not know that. Then can use the DataMember, ValueMember flexibility. Thx. However...
 
You are executing the update from a button_click Method - thus the code is executed on the UI thread - thus it will work. My problem is that I am executing from a timer handler - because I need the update at regular intervals (taking samples) - thus the handler is on a different thread and thus, when executed, silently does absolutely nothing.
 
<head scratch>
 
Thx for the code. Educational. (and 'yes' I got it working)
QuestionBinding a DataGridView column to a nullable property, using a ComboBox bound to a non-nullable property.memberBrady Kelly14-May-13 21:20 
I have two objects, PriceRule and WeekDay, and PriceRule has a DayId column I have bound to a ComboBox column in a DataGridView. When I load the grid, if DayId is null, the combo is blank, but as soon as I drop the combo down, I have to select a day. No problem, I can inject an extra empty string day into the combo's data source, but the Id property of WeekDay is not nullable, so I need to do something as clumsy and stupid as insert a false day with Id of -1.
 
How do I catch this -1 and make it null before saving, and vice versa, catch a null DayId and make it -1 when loading?
 
Is there no other way to do what is a bloody common task that MS clearly isn't capable of handling themselves?
QuestionControl hide/show(should be post here, right?)memberkenmaMoon23-Apr-13 21:20 
I'm creating an user control like treeView, in this control, I want to put a button to let my user control hide/show in Owner form.

how could I do?

thanks
AnswerRe: Control hide/show(should be post here, right?)mvpRichard MacCutchan23-Apr-13 21:57 
You already posted this question at http://www.codeproject.com/Messages/4548577/Control-hide-show.aspx[^]. Please choose one forum only and stick to it.
Use the best guess

GeneralRe: Control hide/show(should be post here, right?)memberkenmaMoon23-Apr-13 22:00 
Just delete it in C# forum
GeneralRe: Control hide/show(should be post here, right?)mvpRichard MacCutchan23-Apr-13 22:42 
I don't have authority to do that; but it's important that you read and follow http://www.codeproject.com/Messages/3137519/Forum-Guidelines-PLEASE-READ.aspx[^].
Use the best guess

AnswerRe: Control hide/show(should be post here, right?)mvpEddy Vluggen23-Apr-13 22:50 
kenmaMoon wrote:
how could I do?

Toggle the Visible property?
 
The problem is a logical one; if you hide the control containing the button to toggle visibility, the user will not be able to make it visible again, as the button that toggles it is invisible too.
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]

GeneralRe: Control hide/show(should be post here, right?)memberkenmaMoon23-Apr-13 22:55 
thanks for your reply.
 
yes, but the button is in the userControl, next time I want the user control shown by click the button.
AnswerRe: Control hide/show(should be post here, right?)mvpEddy Vluggen24-Apr-13 6:29 
kenmaMoon wrote:
yes, but the button is in the userControl, next time I want the user control shown by click the button.

Re-read what I wrote; the button will be invisible if you hide the container it's in. You cannot click an invisible button.
 
Either put the button somewhere else and have it toggle the Visible property, or put the button somewhere on location (0,0) and resize the control to shrink to the size of the button.
 
Third, best option; throw the button and the control you wish to show/hide on a new usercontrol.
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]

QuestionC# Winform controls not drawingmemberMember 783446019-Apr-13 7:01 
I am working on a heavily used winform C# application.
 
I have a user control, that has 3 textboxes and it can contain another user control. user can add n number of main user control on the form. due to this, if the user adds more than 20 controls, after the 20th control, the UI doesnt show anything. It is not giving any exception, its simply not drawing the controls? My application is not exceeding GDI objects
 
Also the textbox is using WPF textbox.
 
All suggestions welcome. Thanks.
AnswerRe: C# Winform controls not drawingmvpEddy Vluggen22-Apr-13 8:52 
Member 7834460 wrote:
after the 20th control, the UI doesnt show anything.

Does that mean that "20 items" is the maximum that "fit" on your form? It might be creating the rest of them on the non-visible area.
 
Does it have a ScrollViewer where you put the children in? Any scrollbars set?
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
  
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]

QuestionChanging BackColor for tabControlmember_katon_11-Apr-13 2:54 
Hello!
Gray BackColor is not suitable for my application GUI. Tell me how it is possible to change the background color of the control.
AnswerRe: Changing BackColor for tabControlmemberAlan N11-Apr-13 3:48 
So what happens when you change the value of the BackColor property?
GeneralRe: Changing BackColor for tabControlmember_katon_11-Apr-13 4:29 
Nothing ... )) msdn: "This member is not meaningful for this control"
AnswerRe: Changing BackColor for tabControlmvpDave Kreskowiak11-Apr-13 5:02 
Did you read this[^]?
 
You'll have to custom draw the tab control yourself to change the color.

QuestionHow to link drawings on on-line maps to the mapmemberMember 843537226-Mar-13 11:40 
I'm using Visual C# 2010 Express.
I've written code to display Provider maps on my form.
I can draw lines on the maps, and capture the latitude / longitude from the map.
My problem is that when I pan or zoom the map, my drawn line stays in one place; it doesn't move or resize with the map.
I'm using a gMap control to load the provider maps as below:
private void Form1_Load(object sender, EventArgs e)
        {
            // Initialize map:
            //gMapControl1.MapProvider = GMap.NET.MapProviders.BingMapProvider.Instance;
            gMapControl1.MapProvider = GMap.NET.MapProviders.ArcGIS_Topo_US_2D_MapProvider.Instance;
            GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;
            gMapControl1.Position = new GMap.NET.PointLatLng(39.401389, -077.986111); //mrb
            gMapControl1.Zoom = 10;
 
I've created an Overlay for my form, and I'm drawing on the overlay as below:
private void graphicalOverlay1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            Pen fl = new Pen(Color.Red, 3.0f);
            e.Graphics.DrawLine(fl, x_start, y_start, xx, yy);
 
        }
 
Perhaps I shouldn't be drawing on the Overlay. But I don't know how to just draw on the providers image.

Any direction to "lock" my drawn lines with the map would be appreciated.
Thanks
AW
AnswerRe: How to link drawings on on-line maps to the mapmemberBernhard Hiller26-Mar-13 22:47 
e.Graphics.DrawLine(fl, x_start, y_start, xx, yy); uses pixel values, not geo coordinates. You have to get the latitude/longitude values for your lines, the transform them into pixels using the zoom and offset values of the underlying map.
GeneralRe: How to link drawings on on-line maps to the mapmemberMember 843537227-Mar-13 0:35 
Bernhard;
 
Thank you for reading my post question and replying.
I'm getting the lat/long coordinates with this:
       private void gMapControl1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                double lat = gMapControl1.FromLocalToLatLng(e.X, e.Y).Lat;
                double lng = gMapControl1.FromLocalToLatLng(e.X, e.Y).Lng;
                //------------------------------------------------
This returns decimal degrees which I then convert to dd-mm-ss.sss.
I was using the following to paint my lines on the provider map, which does work to paint the lines;
        private void gMapControl1_Paint(object sender, PaintEventArgs e)
        {
 
            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            Pen fl = new Pen(Color.Red, 3.0f);
            e.Graphics.DrawLine(fl, x_start, y_start, xx, yy);
But x_start, y_start, xx, yy are nothing more than screen coordinates; just like with the overlay code. And when I pan or zoom, the map moves but my drawn lines stay in the same place relative to the screen.
               x_start = e.X;
                y_start = e.Y
Are you saying that I need to pass the geo coordinates to xx, yy to draw the lines on the providers map?
I don't understand your statement; "then transform them into pixels using the zoom and offset values of the underlying map".
GeneralRe: How to link drawings on on-line maps to the mapmemberMember 843537227-Mar-13 1:53 
Oh, I think I understand what you meant!
I need to do something like
Double map_x equals gMapControl1.FromMapLatLngToLocal(PiontLatLng Point);
Then when I pan or zoom, just redraw my lines.
 
Can you provide the proper syntax for MapLatToLocal ?
GeneralRe: How to link drawings on on-line maps to the mapmemberBernhard Hiller27-Mar-13 22:18 
That's the way to go. But I do not know the functions provided by the control. Why don't you ask the author - there is a section below his article for taht purposes, isn't it?
QuestionNeed guidance for chat conversion UI area designing (win form c#)memberTridip Bhattacharjee25-Mar-13 5:03 
people often develop chat apps and they display chat conversion between two people in simple text box or rich text box. i want to develop a chat apps where i want to design chat conversion UI area look like Skype.
 
1) Skype chat conversion area show the conversion where other user name show as with different color
 
2) user can copy text from chat conversion area by mouse selection
 
3) chat conversion area is capable of showing emoticons.
 
4) chat conversion area can show progress bar when one user send file to other then progress bar is show at two end.
 
so here i am uploading few screen shot of Skype chat conversion area as a result you guys can visualize and can understand what kind of UI i want to develop. please click on the two link to better understand what i am talking about.
http://social.msdn.microsoft.com/Forums/getfile/262465[^]
 
http://social.msdn.microsoft.com/Forums/getfile/262468[^]
the problem is i am not being able to take decision how to develop chat conversion window where i need to show chat conversion data between two user and user name too. also that area must have capability of showing emoticon and progress bar and images.
 
so just suggest me which control i should use to develop chat conversion windows.
 
1) should i use rich text box ?
 
2) should i use datagridview ?
 
2) should i use web browser control ?
 
i need something which can show user name and user chat data and also emoticon and progress bar.
 
please guide me how to develop. if possible give me some c# code. thanks
tbhattacharjee

AnswerRe: Need guidance for chat conversion UI area designing (win form c#)mvpEddy Vluggen25-Mar-13 8:18 
Tridip Bhattacharjee wrote:
please guide me how to develop
Use a rich-text box. Hardest part in a chat-application will be the server. After that, it's doing the messaging on a background-thread in the client, to keep the UI nicely responsive. The UI itself is hardly relevant at that point.
 
I'd start with a plain textbox; once it works, make a backup. Then yank out that textbox, plugin a RTB. Or a WebBrowser. Or something more complex. (FWIW, example seems like a list of a custom-control, consisting of 2 labels and a HTML-capable label in the middle)
 
The datagridview would be the fastest of those controls. The browser would be ideal, given that you can simply embed emotes as pictures in the text.
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]

GeneralRe: Need guidance for chat conversion UI area designing (win form c#)memberTridip Bhattacharjee25-Mar-13 9:33 
u said :- FWIW, example seems like a list of a custom-control, consisting of 2 labels and a HTML-capable label in the middle
 
what is the meaning of FWIW? where to download it.
tbhattacharjee

GeneralRe: Need guidance for chat conversion UI area designing (win form c#)mvpEddy Vluggen25-Mar-13 9:39 
Tridip Bhattacharjee wrote:
what is the meaning of FWIW?

FWIW is "For What It's Worth". You can build a UserControl, drop two labels and a browser on there, and you'd have something similar.
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]

JokeRe: Slow Graphics in Windows 8 [modified]mvpMaciej Los19-Apr-13 6:23 
Disable Aero for Win8 Wink | ;)

modified 19-Apr-13 15:36pm.

GeneralRe: Slow Graphics in Windows 8subeditorWalt Fair, Jr.19-Apr-13 7:24 
If you figured out how to disable Aero in Win 8, I'd love to hear about it. I thought about that first.
CQ de W5ALT

Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software


General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web03 | 2.6.130617.1 | Last Updated 18 Jun 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid