|
Yes, but you may want to ask in the correct forum[^], or look at the EditCommandColumn.UpdateText property documentation in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Obviously I am a newbie to programming. I need help with a windows form. I have created objects on the form and they are all working fine, but I would like to capture the return key and make it act like they clicked the OK button.
Thanks for the help,
Daniel
|
|
|
|
|
On your form in the designer, set it's AcceptButton property to the button your using for OK.
RageInTheMachine9532
|
|
|
|
|
In addition, you can set the DialogResult for that button to OK if you want it to return DialogResult.OK if you used ShowDialog on your Form . This also sets the Form.DialogResult property if you want to determine which button was clicked that closed the form (since setting the Form.DialogResult property also closes the Form ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
For .NET development - if you don't plan on supporting clients using other technologies - you may want to look at .NET Remoting instead. It is a much more powerful, more flexible technology and takes care of the communications automatically. The simplest designer just uses a shared assembly which defines interfaces that the server implements and that the clients user to communicate with the server through a proxy. When using the TcpChannel provided by the .NET Framework Class Library (FCL), you can even have events so that when a client sends a message to the server an event is raised and other clients can get the message immediately. If you're writing your own socket-based chat, you have to handle all this yourself.
In such a case, you need to keep track of connected clients (which .NET Remoting can also do for you pretty easily, though you could use something similar to...) by storing them in a list or something and associate them to each other were appropriate.
If you're having problems with the applications you've found on this site, then you should be specific about what those problems are and you should post questions on the articles' message boards since they're specific to that article.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you Heart! Im gonna try the Remoting thing then
- Up The Irons, Morten Kristensen
|
|
|
|
|
Hi,
I'm writing a program based on an Access Database.
I need to create this database while installing the Application Installer.
While reading Visual Studio documentation, I saw I have to use the SQL Keyword CREATE DATABASE. This is ok for Sql Server, but not for Access.
How can I do ?
Any idea is welcome.
Thanks.
|
|
|
|
|
You either need to use DDL to create a database for Access, or just embed an empty .mdb (Jet Database) as an embedded resource in your assembly that contains the installer and just extract it (if you mean the Installer class). If you're using an installation package like Windows Installer (for which VS.NET contains a couple different projects for creating them), then you could just deploy an empty .mdb that way and put it wherever you need to.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Your right, the Jet engine doesn't know what to do with CREATE DATABASE...
Wouldn't it be alot easier to include a blank copy of your (database).MDB file with your installer?
RageInTheMachine9532
|
|
|
|
|
I have run into an issue in C# / .Net where the control box will not close the form when the user clicks on it.
When my app initially runs, it works fine, but after a while it does nothing when clicked on. I have multiple apps that act in this manner.
Has anyone else run into this? Is there a fix for it?
dpb
Darryl Borden
Principal IT Analyst
darryl.borden@elpaso.com
|
|
|
|
|
This commonly happens when a multi-threaded app has different threads setting properties on the controls that were created in a different thread, or when unhandled exceptions occur during instantiation of the main application form (the form used in the call to Application.Run ). First go through and make sure that you're handling all exceptions that could occur during instantiation of your child controls and that no worker threads are setting properties (and many times even getting properties) or calling methods on the controls from those threads (see Control.InvokeRequired and Control.Invoke in the .NET Framework SDK for more information).
A work-around is to use Application.Quit for your File->Exit (or whatever) menu instead of just calling Close on your form.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hallo, my name is Axel. I´m in process of learning C#. and I want to realize the following problem:
- On a moblile computer runs a client, on my workstation a server application. I want to send simple commands from client to server. Depending on the received command the server application should do something (for example: open a picture, start internet explorer...)
- I want the server application to start once
so that the the client is (as often as necessary) able to connect/disconnect with the server to send data
- I've just tried a solution like the following, but it is not so good:
private void timer1_Tick(object sender, System.EventArgs e)
{
string[] Antwort = {"answer 1","answer 2","answer 3","answer 4"};
byte[] b = new byte[1];
Socket s = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
Socket sa;
try
{
s.Bind(new IPEndPoint(IPAddress.Any,65000));
s.Listen(1);
sa = s.Accept();
do
{
sa.Receive(b);
if (b[0] > 0)
{
this.statusBarServer.Text = "Server open";
if(b[0] <6)
{
this.statusBarServer.Text = "send back: "+ answer[b[0]-1];
sa.Send(Encoding.ASCII.GetBytes(answer[b[0]-1]));
}
else
sa.Send(Encoding.ASCII.GetBytes("wrong question"));
}
else
{
sa.Send(Encoding.ASCII.GetBytes("CU"));
}
}
while (b[0] >0);
sa.Close();
s.Close();
this.statusBarServer.Text = "Server close";
}
catch(SocketException ex)
{
this.statusBarServer.Text = ex.Message;
}
}
I don't like using a timer for this particular problem. Can someone give me any help?
Thanks,
Axel
|
|
|
|
|
Just have the server accept connections in a non-terminating loop. It gets the client Socket connection and spawns a new thread that handles the client communications. This is basically how all the major daemons work.
Also, you may want to look into .NET Remoting and host the remoting object either in a Windows Service or IIS. It's very flexible and very powerful, although it has a pretty steep learning curve if you're not familiar with it. It's definitely worth it, though, if you're developing distributed apps for the .NET Framework.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
What is wrong with writing a simple loop without closing the server down?
Or look into the Socket.BeginAccept method if you want something that will perform better.
If you don't kill me you will only make me stronger
That and a cup of coffee will get you 2 cups of coffee
|
|
|
|
|
Yeah, using a timer to start a listener is a REALLY bad idea. This will only try and start a new listener on every timer tick, even if the first one hasn't complete any kind of task. If your timer is launching a new listener every second, or even every minute, ... Uggggh, I don't even want to think about it...
RageInTheMachine9532
|
|
|
|
|
I've got a service that is dependent on some files, and checks for modification of the files (thanks to everyone who helped me understand how to do this). Now that I've got that done, I think it would be nice to be able to have another thread whose sole responsibility is to check the time stamp on these files and reload the data when needed, that way the users don't have to wait while data is reloadedl
My initial thought is to either create another thread and have it sleep or use timers to accomplish this, however I do not know where to place this code in my service. I don't think I would want to put it in the constructor otherwise it would get called whenever anyone made a request, and would result in mutliple threads doing the same thing. Is there anyway to create a new thread when the service starts up (before the initial request) that will do this?
Thanks for your help.
|
|
|
|
|
[edit]Doh. read web service as windows service. Please disregard. [/edit]
The system.timers.Timer is good for this. Add the timer to your service object. Then set the interval and assign the event in your constructor. Then you just need to start and stop the timer in your service start and stop events.
If you need to make absolutely sure that the timer will not be executing after you leave the stop event , you need to do your own thread syncronization, but in most cases you don't need to worry about it.
If you need to schedule multiple jobs look for the scheduled timer CP article I posted a few weeks ago.
If you don't kill me you will only make me stronger
That and a cup of coffee will get you 2 cups of coffee
|
|
|
|
|
I don't remember if you're the same guy I and nother guy were helping before, but look at the Cache class in the .NET Framework. You can access this in your Web Service using the Context property (HttpContext ), which gives you the Cache object. You can add a CacheDependency on that file so that if it changes the cached item is invalidated, so that you read-load the data.
If you look at the documentation for the Cache.Add method, however, you'd notice a CacheItemRemovedCallback parameter (the last parameter). If you didn't want to have the user wait until the data is reloaded, you could add a callback that loads the data as soon as the cache item is invalidated and removed from the cache.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yes that was me, and thank you for your help. I've got the call back working to where it will remove the cached data on a change. However, in the method that does that, I also try to reload and then re-add the data, but it doesn't re-add.
Here is the method:
<br />
public void TPMDataRemovedCallback(String k, Object v, CacheItemRemovedReason r){<br />
TPMreason = r;<br />
string tpmDataKey = "TPMDATA";<br />
if(onTPMDataRemove == null)<br />
onTPMDataRemove = new CacheItemRemovedCallback (this.TPMDataRemovedCallback);<br />
DateTime NoAbsoluteExpiration = Cache.NoAbsoluteExpiration;<br />
TimeSpan NoSlidingExpiration = Cache.NoSlidingExpiration;<br />
CacheItemPriority Priority = CacheItemPriority.AboveNormal;<br />
Context.Cache.Remove(tpmDataKey);<br />
System.IO.FileInfo fileInfo = new System.IO.FileInfo(tpmFileName);<br />
tpmData = tpm.LoadTPM();<br />
try{<br />
Context.Cache.Add(tpmDataKey,this.tpmData,this.tpmDataCacheDependency,NoAbsoluteExpiration,NoSlidingExpiration,Priority,onTPMDataRemove);<br />
}<br />
catch(System.Exception caught){<br />
Console.WriteLine("Exception == " + caught);<br />
}<br />
}<br />
I don't see an exception get caught, but the cache at Context.Cache[tpmDataKey] doesn't contain anything. What am I doing wrong?
|
|
|
|
|
Did you step through your code and see if this method even gets called? You must first call this method (or a similar one) to load the data into the cache and create the callback.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yes, I've stepped through the method. It gets called, and there is something on the cache when it gets called. Once that method is called the remove succeeds, as does the loading of the data. However when I call add it doesn't seem to add it to the cache, however upon the next request it sees that there is nothing on the cache, loads the data, and readds it with no problem, and what I don't understand is that I call add then with the same parameters as I do in the RemovedCallback method, only this time it does add it.
|
|
|
|
|
First, you shouldn't call Cache.Remove : the callback is invoked after the item - and remember there could be multiple objects in the cache with different keys - is removed, but you need to be mindful of the key. The following example should work:
private const string KEY1 = "File1.txt";
private const string KEY2 = "File2.txt";
private void CacheFile(string key)
{
if (key == null) throw new ArgumentNullException("key");
if (key.Length == 0) throw new ArgumentException("Invalid key.");
if (Cache[key] == null)
{
string path = Server.MapPath("/docs/" + key);
using (StreamReader reader = new StreamReader(path))
{
Cache.Add(
key,
reader.ReadToEnd(),
new CacheDependency(path),
Cache.NoAbsoluteExpiration,
Cache.NoSlidingExpiration,
CacheItemPriority.AboveNormal,
new CacheItemRemovedCallback(CacheItemRemoved));
}
}
}
private void CacheItemRemoved(string key, object value,
CacheItemRemovedReason reason)
{
if (key == KEY1) CacheFile(KEY1);
else if (key == KEY2) CacheFile(KEY2);
}
public string File1Content
{
get
{
CacheFile(KEY1);
return Cache[KEY1];
}
}
public string File2Content
{
get
{
CacheFile(KEY2);
return Cache[KEY2];
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
:-OI'm printing a windows form by looping thru all the controls on the form, but I realized the form needed more than one page to fully print. I know I need to loop thru the controls but not with a 'for' loop. I need to increment each control with a counter of sorts so if I set the hasmorepages, the code will know which control to start with on the next page, but I can't get anything to work. help?
Here's the function that works, but without printing more data on the next page:
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
.......
.......
Graphics g = e.Graphics;
DrawAll(e.Graphics, e);
foreach(Label lbl in panel1.Controls)
{
g.DrawString(lbl.Text, lbl.Font, Brushes.Black, lbl.Bounds.Left*scalex, lbl.Bounds.Top, new StringFormat());
}
}
Nancy
|
|
|
|
|
Use a for loop instead with the current index as a field in your class initialized to 0. then use a for loop like so:
for ( ; i < Controls.Count; i++)
{
Label lbl = Controls[i] as Label;
} Here, i would be a field in your class declared something like:
private int i = 0; FYI, your foreach loop has a major flaw: if a control in the Controls collection is not a Label , an exception would be thrown. This may not be applicable in your application now (if panel1 contains only Label s), but if you ever add anything else your code will throw a cast exception.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|