|
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);
}
}
} The timer is based on the Windows message-pump;
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
If you can't read my code, try converting it here[^]
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
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);
L2.Add(33);
}
private void button2_Click(object sender, EventArgs e)
{
((CurrencyManager)this.BindingContext[L1]).Refresh();
}
}
}
|
|
|
|
|
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;
}
}
|
|
|
|
|
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.
Thx for the code. Educational. (and 'yes' I got it working)
|
|
|
|
|
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?
|
|
|
|
|
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
|
|
|
|
|
|
Just delete it in C# forum
|
|
|
|
|
|
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
If you can't read my code, try converting it here[^]
|
|
|
|
|
thanks for your reply.
yes, but the button is in the userControl, next time I want the user control shown by click the button.
|
|
|
|
|
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
If you can't read my code, try converting it here[^]
|
|
|
|
|
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.
|
|
|
|
|
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
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello!
Gray BackColor is not suitable for my application GUI. Tell me how it is possible to change the background color of the control.
|
|
|
|
|
So what happens when you change the value of the BackColor property?
|
|
|
|
|
Nothing ... )) msdn: "This member is not meaningful for this control"
|
|
|
|
|
Did you read this[^]?
You'll have to custom draw the tab control yourself to change the color.
|
|
|
|
|
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)
{
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);
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
|
|
|
|
|
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.
|
|
|
|
|
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".
|
|
|
|
|
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 ?
|
|
|
|
|
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?
|
|
|
|
|