|
hi
i dont get it
please explane more..
thanks
|
|
|
|
|
I have created a Windows Forms app in which I have a custom numeric edit box that is bound to an item in a DataSet, and a TrackBar control that I want to mirror the value in the edit box (i.e. changes to the number in the edit box effect the TrackBar and changes to the TrackBar are reflected in the edit box). Unfortunately I can not bind the TrackBar to the same value as the edit box because the edit box can contain values between .01 and 1000 (and it is my understanding that the TrackBar can only handle integers). It seems straight forward enough to trap the Validated event of the edit box and update the location of the TrackBar accordingly (after applying scaling factor – i.e. multiplying by 100 so min value is 1 and max value is 100000, and converting to int). The problem that I am having comes from trying to adjust the bound edit box value programmatically in the Scroll event of the TrackBar. In order to get the functionality that I want I had to add the following code to the Scroll event handler:
private void ctrlPowerTrackBar_Scroll(object sender, System.EventArgs e)<br />
{<br />
(this.cmMyCurrencyManager.Current as DataRowView).EndEdit();<br />
<br />
this.dsMyDataSet.tblModelSettings[0].itemPower = this.ctrlMyNumericEdit.Value / 100.0;<br />
}
Could some one explain to me why I must call EndEdit(). If I remove the call to EndEdit(), changes to the TrackBar update the edit box as I would expect – at least until I change a value in any of the edit boxes that are bound to the same DataSet as the edit box that I am trying to update programmatically. It appears that modifying the value of a bound edit box causes BeginEdit() to be called for that row, but I haven’t been able to find any documentation on when EndEdit should be called. I’m not sure that calling EndEdit is the correct thing to do - I just stumbled across it and it seems to work. (If it helps, I should also mention that I am only using the DataSet for the purpose of data binding and as a means of easily storing and recalling control values in presets – i.e. there is no underlying database that will be updated with the data in my DataSet, and there will never be more than one row in this DataSet)
Thanks for your help.
|
|
|
|
|
I have a game that I have written and I have a form timer that tracks the time in the current game. Basically the counter is set to every 1000 miliseconds and counts the time the current game is in progress.
The problem is I am using a system.threading.wait() to pause the display of two cards for 1.5 seconds and it is also pausing the game clock for 1.5 seconds.
Is there a way I can still pause the thread but not pause the game clock, such as putting the timer in a seperate thread?
|
|
|
|
|
|
In Your case Threading.Timer would be th ideal one.
James
|
|
|
|
|
Hi all,
I have a question on how to properly implement network broadcasts.
Our network is divided in subnets and I need help (it is probably more of a networking question than code)
To broadcast I use this code:
IPEndPoint ep = new IPEndPoint(IPAddress.Broadcast, 8300);
UpdClient client = new UdpClient();
client.Send(...,ep);
To receive I use this code:
IPEndPoint ep = new IPEndPoint(IPAddress.Any, 0);
UpdClient client = new UdpClient(8300);
byte [] buffer = client.Receive(ref ep);
My machine is on the 192.168.1.xxx subnet and all machines on the 1.xxx network receive the broadcast, but machines on the 192.168.8.xxx network do not. What IP address should I use in the sending portion to make sure I broadcast to the 8.xxx network?
|
|
|
|
|
OK, this is how subnetting works:
An IP-Address is 32 Bit long. The first part determines the Network, the second part identifies the Host.
Your network class is C, which means: the first 24 Bit are Network, the last 8 Bit are host. Subnet-Mask is 255.255.255.0 (which means exactly the same: all bits set to 1 are part of the Network-ID, the bits set to 0 are part of the Host-ID. There never are any 0s between 1s, so its always ...11111000... and NEVER ...110110000... etc.)
What is that subnet-mask good for, if the network-class already contains the necessary information?
That is VERY simple:
Using an IP-Address from ANY Network and the corresponding subnet mask, you can easily derive the broadcast-address of that network.
Your code doesnt work cause IPAddress.Broadcast is 255.255.255.255 (which means "EVERY ADDRESS ON ALL NETWORKS" and is probably filtered by your L3-switches or routers).
Try the following:
If you need to contact all hosts in the 192.168.8.0 Network, use a bitwise-or of one host-address (e.g. 192.168.8.4) and the inverted subnet-mask (e.g. 0.0.0.255). That will return the broadcast-address of the network (in this case, 192.168.8.255).
If you need to calculate the Network-Address, use a bitwise-and instead and dont invert the subnet-mask.
Remember the following:
The first address in a subnet always is the Network Address, the last address always is the Broadcast.
If you are not using CIDR, the following is true:
Subnetmask for Class-A Networks: 255.0.0.0
Subnetmask for Class-B Networks: 255.255.0.0
Subnetmask for Class-C Networks: 255.255.255.0
Cheers
Sid
|
|
|
|
|
|
Hi
I write a program which P/Invoke a unmanaged function calling "CreateWindow(..)" to create a window and the window handle is a global variable at the unmanaged side. When the managed program stop, how to destory the window to free the memory? Or the window will dispose after the caller program stop?
Thanks
|
|
|
|
|
P/Invoke DestroyWindow to free the handle.
|
|
|
|
|
Hello guys, I'm trying to make a client/server com+ application... My com+ class is done and enterprise services really knows it like com+ but when I try to "Export" this application at enterprise services it just enables me to Export as Server Application and I want to Export as Application Proxy.
How to export a .NET COM+ class at enterprise services as an application proxy or how to make this communication beteween 2 pcs.
Thanks...
Wender Oliveira
.NET Programmer
|
|
|
|
|
Hello:
In a web form I’m using a place holder, into it, which contains or not a web user control created ado with next code:
Example.Controls.C1lear();
Control control = this.Page.LoadControl("WebUserControl3.ascx");
Example.Controls.Add(control);
Where Example is my place holder.
Is there some way to ask if place holder contains a web user control or if it’s empty?
I’ll thank you your help.
A.L.
El hombre que tiene amigos debe mostrarse amigo...
|
|
|
|
|
Example.Controls.Count
Anger is the most impotent of passions. It effects nothing it goes about, and hurts the one who is possessed by it more than the one against whom it is directed.
Carl Sandburg
|
|
|
|
|
Thanks you Rob, also work with Example.HasControls();
El hombre que tiene amigos debe mostrarse amigo...
|
|
|
|
|
I have datagrid that I'm filling with rows, if the rows don't fill up the size of the grid, then I'm adding new empty rows from my dataview in my derived datagrid. The problems that comes up is that when im sorting the columns the empty rows are also sorted (not the last one, and i don't know why the last one is not sorted). Qestion: can i somehow sort the filled rows and just letting the empty (DBNULL) just be in the bottom of my grid?
|
|
|
|
|
I wonder how I can change the highlight color of a ListView control when an item is selected. Thanks in advance.
Radgar
"Imagination is more important than knowledge." - Albert Einstein
|
|
|
|
|
Hi,
I have a table in a Dataset that contains rows for many products. Each row contains Rate of that product. I want to create a new table which would contain Rate of all products discounted at 20%. Is it possible. If yes how?.
My preferred approach is rather then reading each row and then getting the rate i want to apply this dicount for all products at one time.
Nishant
|
|
|
|
|
Hi Nishant,
You can DataColum.Expression property for doing this. This allows you to calculate the values of a colum.
1) Create a new colum with a proper data type.
2) Set the expression property of that coloum . (Ex "rate * 0.8")
3) Add this colum to the table.
The new column is filled with the calculated value.
Hope this will help you.
Regards
SGS
|
|
|
|
|
Thanks a lot, it worked.
But one more thing can i have this column in some other table...
|
|
|
|
|
Hi people,
I have a running small windows forms application on 1.0 and 1.1, but when I use the code on 2.0 beta, it says that the thread cannot access an object that it hasn't created . Can anyone check this out for me please? I have 2 files, one called Main.cs, which is the main program and then I have Ticker.cs which is another window class called from Main. I will post below the whole code for both files, if anyone has any clue about that.
I am using SharpDevelop for 1.1 and Visual C# Express 2005 beta for 2.0
Main.cs
<br />
<br />
using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
using System.Threading;<br />
<br />
<br />
namespace Exercice1<br />
{<br />
public class Form1 : System.Windows.Forms.Form<br />
{<br />
private System.Windows.Forms.Label label1;<br />
private System.Windows.Forms.Label lblText;<br />
private System.Windows.Forms.Button btnClose;<br />
private System.Windows.Forms.Timer timer;<br />
private System.ComponentModel.IContainer components;<br />
private System.Windows.Forms.ProgressBar progressBar1;<br />
<br />
<br />
<br />
<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
<br />
}<br />
<br />
protected override void Dispose( bool disposing )<br />
{<br />
if( disposing )<br />
{<br />
if (components != null) <br />
{<br />
components.Dispose();<br />
}<br />
}<br />
base.Dispose( disposing );<br />
}<br />
<br />
#region Windows Form Designer generated code<br />
private void InitializeComponent()<br />
{<br />
<br />
this.components = new System.ComponentModel.Container();<br />
this.timer = new System.Windows.Forms.Timer(this.components);<br />
this.label1 = new System.Windows.Forms.Label();<br />
this.lblText = new System.Windows.Forms.Label();<br />
this.btnClose = new System.Windows.Forms.Button();<br />
this.progressBar1 = new System.Windows.Forms.ProgressBar();<br />
this.SuspendLayout();<br />
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));<br />
this.label1.Location = new System.Drawing.Point(16, 16);<br />
this.label1.Name = "label1";<br />
this.label1.Size = new System.Drawing.Size(264, 23);<br />
this.label1.TabIndex = 0;<br />
this.label1.Text = "Welcome";<br />
this.lblText.Location = new System.Drawing.Point(16, 56);<br />
this.lblText.Name = "lblText";<br />
this.lblText.Size = new System.Drawing.Size(264, 23);<br />
this.lblText.TabIndex = 1;<br />
this.lblText.Text = "Loading XYZ...";<br />
this.btnClose.Location = new System.Drawing.Point(208, 128);<br />
this.btnClose.Name = "btnClose";<br />
this.btnClose.TabIndex = 2;<br />
this.btnClose.Text = "Cancel";<br />
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);<br />
this.progressBar1.Location = new System.Drawing.Point(16, 96);<br />
this.progressBar1.Name = "progressBar1";<br />
this.progressBar1.Size = new System.Drawing.Size(264, 23);<br />
this.progressBar1.Step = 1;<br />
this.progressBar1.Minimum=0;<br />
this.progressBar1.Maximum=20;<br />
this.progressBar1.TabIndex = 3;<br />
this.timer.Enabled = true;<br />
this.timer.Interval = 300;<br />
this.timer.Tick += new System.EventHandler(this.timer_Tick);<br />
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
this.ClientSize = new System.Drawing.Size(294, 175);<br />
this.Controls.AddRange(new System.Windows.Forms.Control[] {<br />
this.progressBar1,<br />
this.btnClose,<br />
this.lblText,<br />
this.label1});<br />
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;<br />
this.Name = "SplashForm";<br />
this.Text = "Loading MyApp...";<br />
this.Load += new System.EventHandler(this.SpashForm_Load);<br />
this.ResumeLayout(false);<br />
<br />
}<br />
#endregion<br />
<br />
private void btnClose_Click(object sender, System.EventArgs e)<br />
{<br />
this.DialogResult = DialogResult.Cancel;<br />
this.Close();<br />
}<br />
<br />
private void timer_Tick(object sender, System.EventArgs e)<br />
{<br />
if (progressBar1.Value != progressBar1.Maximum)<br />
{<br />
progressBar1.PerformStep();<br />
<br />
}<br />
else<br />
{<br />
this.timer.Tick -= new System.EventHandler(this.timer_Tick);<br />
Ticker t1 = new Ticker();<br />
t1.Show();<br />
this.Hide();<br />
}<br />
<br />
}<br />
<br />
private void SpashForm_Load(object sender, System.EventArgs e)<br />
{<br />
if (progressBar1.Value == progressBar1.Maximum)<br />
{<br />
<br />
}<br />
}<br />
protected override void OnClosing(CancelEventArgs e) <br />
{<br />
this.Dispose();<br />
Environment.Exit(0);<br />
<br />
}<br />
[STAThread]<br />
static void Main() <br />
{<br />
Application.Run(new Form1());<br />
}<br />
}<br />
<br />
<br />
}<br />
<br />
Ticker.cs
<br />
using System;<br />
using System.Windows.Forms;<br />
using System.ComponentModel;<br />
using System.Drawing;<br />
using System.Threading;<br />
using System.IO;<br />
<br />
namespace Exercice1 {<br />
<br />
public class Ticker : Form {<br />
<br />
Label label1, label2;<br />
<br />
String[] newsItems =<br />
{ "Safest Aerobic Machine Launched",<br />
"First Dog Cloning Is Only Days Away",<br />
"Reviving the Extinct Tasmanian Tiger" };<br />
<br />
String[] businessItems =<br />
{ "FirstMeasure Software to Go Nasdaq",<br />
"MFMF Directors To Meet For The First Time",<br />
"First Sign of Economic Recovery Finally At Sight",<br />
"Euro Hits Record Low (Again)" };<br />
<br />
<br />
<br />
public Thread NewsThread,BusinessThread;<br />
<br />
<br />
public Ticker() {<br />
Initialize();<br />
StartThread();<br />
}<br />
#region Windows Form Designer generated code<br />
private void Initialize() {<br />
this.Height = 100;<br />
<br />
label1 = new Label();<br />
label2 = new Label();<br />
<br />
label1.Width = 280;<br />
label1.Height = 30;<br />
label1.Location = new Point(1, 10);<br />
label1.TextAlign = ContentAlignment.MiddleRight;<br />
<br />
label2.Width = 280;<br />
label2.Height = 30;<br />
label2.Location = new Point(1, 40);<br />
<br />
this.Controls.Add(label1);<br />
this.Controls.Add(label2);<br />
}<br />
#endregion<br />
<br />
private void StartThread() {<br />
<br />
NewsThread = new Thread(new ThreadStart(MoveLeft));<br />
BusinessThread = new Thread(new ThreadStart(MoveRight));<br />
NewsThread.Start();<br />
BusinessThread.Start();<br />
}<br />
<br />
private void MoveLeft() {<br />
string labelText;<br />
while(true)<br />
{<br />
<br />
foreach(string item in newsItems)<br />
{<br />
labelText = item;<br />
label1.Text=labelText;<br />
<br />
for (int i=280;i>1;i--)<br />
{<br />
label1.Location = new Point(i, 10);<br />
<br />
Thread.Sleep(10);<br />
}<br />
<br />
Thread.Sleep(500);<br />
}<br />
}<br />
}<br />
<br />
private void MoveRight() <br />
{<br />
string labelText;<br />
<br />
while(true)<br />
{<br />
foreach(string item in businessItems)<br />
{<br />
labelText = item;<br />
label2.Text="";<br />
int textLength = labelText.Length;<br />
<br />
for (int i=0;i<textLength;i++)<br />
{<br />
label2.Text+=labelText[i];<br />
Thread.Sleep(50);<br />
}<br />
<br />
<br />
Thread.Sleep(500);<br />
}<br />
}<br />
}<br />
<br />
protected override void OnClosing(CancelEventArgs e) {<br />
<br />
NewsThread.Abort();<br />
BusinessThread.Abort();<br />
this.Dispose();<br />
Environment.Exit(0);<br />
<br />
}<br />
<br />
<br />
}<br />
}<br />
<br />
Thank you!
Talal
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
This is most likely occurring in your tick event handler. Basically, Windows Forms controls (like your progress bar), and indeed all Win32 common controls, cannot be accessed on a thread other than the thread that created the control. Check out MSDN for Control.Invoke and Control.BeginInvoke.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Lies of Our Fathers: A Must-Know About Lent
Judah Himango
|
|
|
|
|
thanks!
I will look into that.
Talal
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
You've broken one of the basic rules of Windows UI programming. Only the thread that created the UI can modify the UI. .NET 1.1 doesn't report any exception but I bet you wouldn't have achieved the effect you wanted. .NET 2.0 immediately throws an exception if you try to modify the UI from some other thread.
You'll have to use Invoke/BeginInvoke to marshal the method call on the UI thread.
Regards
Senthil
My Blog
|
|
|
|
|
Hi,
well, the weird thing is that it is actually achieving what I want...After the progressbar finishes, the first window is hidden and the other window opens and you have 2 threads created. One is the right method to move text from right to left and the other is the left method..and they loop forever.
I will try looking into that invoke thing, although I have no idea how it works.
thanks for the tip, I appreciate it
Talal
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
Hi everybody.
I'm retreiving a DateTime from MS sql server, on two different computers.
Both computers have the same definition in ControlPanel > Regional and language options , and same version of .Net (1.1).
When I cast the DateTime to string, (DateTime.ToString() ), I get on computer #1 mm/dd/yyyy, while in computer #2 I get dd/mm/yyyy.
Where is the problem?
Thanks,
Yaakov
|
|
|
|
|