|
and why its crate texboxes together i write different coordinates but they r together
|
|
|
|
|
You can't convert a textbox to a number. You want to use textbox1.Text. Also, use int.TryParse, so it doesn't blow up if it can't convert.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
private void createTextBox()
{
}
private void button1_Click(object sender, EventArgs e)
{
createTextBox();
createTextBox();
}
|
|
|
|
|
Maybe you should do this:
private void createTextBox(string name)
{
TextBox name = new TextBox();
}
private void button1_Click(object sender, EventArgs e)
{
createTextBox(box1);
createTextBox(box2);
} Otherwise they probably would cause an exception if two textboxes are created with the same names.
Virtual1ty
"Any fool can learn from his own mistakes, but a wise man learns from mistakes of others"
|
|
|
|
|
Hi!
I am trying to run a timer in my Form.
The form has a function that is being called from the timer handler but i have a problem.
this is the code:
private static void TimerHandler(Object myObject, EventArgs myEventArgs)
{
starttime.Stop();
starttime.Enabled = false;
Form1_Main();
}
if i use the static on the Hnaler i get this error:
Error 1 An object reference is required for the nonstatic field, method, or property 'Update_Installer.Form1.Form1_Main()' C:\Documents and Settings\Yossi_Tubis\My Documents\Visual Studio 2005\Projects\Update_Installer\Update_Installer\Update_Installer\Form1.cs 124 13 Update_Installer
if i do not use it i get this:
private void TimerHandler(Object myObject, EventArgs myEventArgs)
{
starttime.Stop();
starttime.Enabled = false;
Form1_Main();
}
Error:
Error 1 An object reference is required for the nonstatic field, method, or property 'Update_Installer.Form1.TimerHandler(object, System.EventArgs)' C:\Documents and Settings\Yossi_Tubis\My Documents\Visual Studio 2005\Projects\Update_Installer\Update_Installer\Update_Installer\Form1.cs 112 31 Update_Installer
The function is in the general Form.
What to do?
Thanks
|
|
|
|
|
ytubis wrote: Form1_Main();
That 2nd error you get - what line of code is the error occurring on? My bet is you have some static timer and you're telling it to send it's Tick event notification to a non-static method.
To solve this, just don't make the timer static, don't make TimerHandler static, and don't make Form1_Main static. Don't make anything static unless there's a specific reason to do so (e.g. if it doesn't need to use any instance members)
|
|
|
|
|
Hi,
I am guessing you are working on an app without a user interface, and are trying to run
everything from your static Main method and feel a need to have everything static then.
The easy solution to that is to immediately create an
object of a new class and make it run; then nothing needs to be static except for
the main method. Example:
static Main(...) {
Test test=new Test();
test.Run();
}
class Test {
Timer timer;
public Test() {
timer=new Timer();
timer.Tick+=new EventArgs(tickHandler);
}
public void Run() {
...
}
public void tickHandler(...) {
...
}
}
BTW: you can put your static Main method inside the Test class if you want to.
It does not need a separate file or class.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
hi friends..
my application (.exe) is running fine on my PC for user Administrator. but when i run the same application for another user (Restriced User Account) on the same PC, it's running the application but upon accessing the registry throguh the program code raising security exception.
"requested registry access is not allowded"
how do i configure .Net Framework Configuration tools in order to run my application (accessing registry throguh program code )
for a restricted user account. i dont want to change the level of
user account.
stephen
|
|
|
|
|
Stephen, applications generally should not require admin privileges to run. You are allowed to access certain registry keys -- would it be feasible to modify your application code to write to the registry in an allowed registry key hive? (e.g. don't write to HKLM, but instead write to HKCU)?
|
|
|
|
|
hi Judah Himango...
thank you for your reply.. it helped me to solve my problem.
now i understood the concept and it works fine with HKCU hive.
stephen
|
|
|
|
|
Hi all,
m new to C# programming.Is there any method by which we can explicitly stop addition of new item to a combo box at runtime?its urgent!!!!causing lot of problem....I'll have 2 handle exception if not stopped properly.please help.
dCodeProvider
(i'll provide 'em later;))
|
|
|
|
|
dCodeProvider wrote: Is there any method by which we can explicitly stop addition of new item to a combo box at runtime?
Yes, you simply don't call the Items.Add method. If you want any further explanation then you'll have to provide some code to feed us.
|
|
|
|
|
dCodeProvider wrote: its urgent!!!!
No, it's not. You're not paying anyone for support, so we volunteers will get to it when we can, not when you demand.
dCodeProvider wrote: causing lot of problem....I'll have 2 handle exception if not stopped properly
Don't add it then. There's no way to stop a call to someComboBox.Items.Add() . The solution is easy - don't add the item in the first place!
|
|
|
|
|
Hi All
Am developing an inventory package in C# 2005. in this customer needs printout of sales in preprinted stationary. right now am following it this way.
On Clicking the grid and print button is selected am writing it to a TEXT file named SALESPRINT.TXT.
AM HAVING PROBLEM FROM THIS PART, AM ABLE TO WRITE TO A TEXT FILE BUT THERE IS ALIGNMENT PROBLEMS. following is the format of the preprinted stationary.
INV DATE xxxxxxxxxx INV NO xxxxxxxxxxxx PAGE NO xxxxx
CUSOTMER ADDRESS1 xxxxxxxxxxxxxxxxx
CUSOTMER ADDRESS2 xxxxxxxxxxxxxxxxx
SL NO SHORT CODE ITEM NAME QTY RATE TOTAL
xx xxxxxx xxxxxxxxxxxxxxxxxxx 10 12.25 122.5
xx xxxxxx xxxxxxxxxxxxxxxxxxx 10 12.25 122.5
xx xxxxxx xxxxxxxxxxxxxxxxxxx 10 12.25 122.5
xx xxxxxx xxxxxxxxxxxxxxxxxxx 10 12.25 122.5
xx xxxxxx xxxxxxxxxxxxxxxxxxx 10 12.25 122.5
xx xxxxxx xxxxxxxxxxxxxxxxxxx 10 12.25 122.5
xx xxxxxx xxxxxxxxxxxxxxxxxxx 10 12.25 122.5
xx xxxxxx xxxxxxxxxxxxxxxxxxx 10 12.25 122.5
xx xxxxxx xxxxxxxxxxxxxxxxxxx 10 12.25 122.5
xx xxxxxx xxxxxxxxxxxxxxxxxxx 10 12.25 122.5
xx xxxxxx xxxxxxxxxxxxxxxxxxx 10 12.25 122.5
xx xxxxxx xxxxxxxxxxxxxxxxxxx 10 12.25 122.5
_______________________________________________________________________________
TOTAL xxxxx
_______________________________________________________________________________
DISCOUNT xxxxx
_______________________________________________________________________________
GT xxxxx
so right now am using string.PadRight & string.PadLeft to specify the positions of contents in the text file. but am finding it difficult to do it. customer is using Dot matrix printer & preprinted continuous sheets for printing this.
So to do this am i doing the right thing and am i on right track ????
Please guide to finish this, if anyone knows how to give line skipping in dot matrix printer pl z tell me how to do
Thanks in Advance
Freelancer
-- modified at 16:01 Thursday 27th September, 2007
|
|
|
|
|
Have you thinked to use crystal reports?
Or create an HTML file instead of an txt?
If is only to print purpose you can build an html
Visit my blog at http://dotnetforeveryone.blogspot.com/
|
|
|
|
|
But its making the print slow, right now am using this way.
PrintTextWrite.WriteLine(PSLNO.PadRight(3) + " " + PKCODE.PadRight(14) + " " + PITEMNAME.PadRight(45) + " " + PQTY.PadLeft(40) + " " + PRT.PadRight(11) + " " + PTOT1.PadLeft(20));
but when size of PITEMNAME increases PQTY,PRATE,PTOT1 will go off the paper
|
|
|
|
|
Hi,
I have written an application (.NET 1.1, Windows.Forms) successfully running on not-Vista. But a customer reported, that under Vista the application is killed by Windows somewhere during his session after clicking a button, which starts a time-consuming calculation. (Other customers have this application running successfully under Vista)
Vista pops up a form
"myApp has stopped working. A problem has caused the program to stop working correctly. Windows will close the program and notify you if a solution is available."
Hm, Windows is able to do that...? Well...
Nevertheless I want to get active to find the error.
Perhaps I should mention that the progress-bar form for that calculation, which runs in a separate thread, is opened successfully immediately before the crash.
Following exception was noted by my application:
System.ObjectDisposedException: Cannot access a disposed object.<br />
Object name: 'myApp'.<br />
at System.Windows.Forms.Control.CreateHandle()<br />
at System.Windows.Forms.Form.CreateHandle()<br />
at System.Windows.Forms.Control.get_Handle()<br />
at System.Windows.Forms.Form.FillInCreateParamsStartPosition(CreateParams cp)<br />
at System.Windows.Forms.Form.get_CreateParams()<br />
at System.Windows.Forms.Control.CreateHandle()<br />
at System.Windows.Forms.Form.CreateHandle()<br />
at System.Windows.Forms.Control.get_Handle()<br />
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)<br />
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)<br />
at System.Windows.Forms.Control.Show()<br />
at ImageIron.this_Load(Object obj, EventArgs ea)<br />
at System.Windows.Forms.Form.OnLoad(EventArgs e)<br />
at System.Windows.Forms.Form.OnCreateControl()<br />
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)<br />
at System.Windows.Forms.Control.CreateControl()<br />
at System.Windows.Forms.Control.WmShowWindow(Message& m)<br />
at System.Windows.Forms.Control.WndProc(Message& m)<br />
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)<br />
at System.Windows.Forms.ContainerControl.WndProc(Message& m)<br />
at System.Windows.Forms.Form.WmShowWindow(Message& m)<br />
at System.Windows.Forms.Form.WndProc(Message& m)<br />
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)<br />
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)<br />
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Does anybody know that problem?
Thanks in advance,
Alex
|
|
|
|
|
AlexZieg71 wrote: Does anybody know that problem?
Yes, you're trying to access a disposed class, an the same exception can be generated by using this code:
Form newForm = new Form();
newForm.Dispose();
newForm.Text = "Hello World!"; You'll have to provide some code or a stack trace for us to help you track down the problem.
|
|
|
|
|
Thanks for your reply! But if I knew the failing code I would be happy to post it here...
I think that it must be a Vista-specific behaviour, because the same application has been running on other Windows-versions for many months now. Perhaps the exception was thrown because my application wanted to continue, but Vista disposed the main Form for some (?) reason...
|
|
|
|
|
I ran into a similar problem. On Vista, .NET seems to run it's garbage collection more frequently or something; because I had code which was accessing an object I had released, and it never complained on XP, but always threw an exception in Vista.
|
|
|
|
|
Hm, I will have a look on this, too. Thanks!
|
|
|
|
|
Are you doing any communication across threads? e.g. thread 2 tells thread 1 to update the progress bar - anything like that?
Alternately, you aren't accessing a progress bar (or any other control) on a thread other than the one that created it, are you?
|
|
|
|
|
No. The main thread creates the progress-bar form in a second thread and updates a progress value which is checked by a Timers.Timer in this second thread 4 times a second.
Is there a known Vista-specific behaviour in multi-threading?
|
|
|
|
|
So, the second thread that creates the progress bar form - is that thread STA? Any thread that creates controls or windows needs to be STA apartment state.
Another thing you might want to check is, are these timers still running in the background when the progress bar form is disposed/closed? I'm picturing some timer or the first thread telling the progress bar form to do something, but it turns out the progress bar form is disposed, causing your exception.
I suspect what you're seeing isn't Vista-specific, but rather, is a race condition that happens only under certain circumstances or perhaps with a certain processor architecture (multicore, hyperthread, etc.) that handles threading differently, causing your race condition to occur more often.
|
|
|
|
|
Yes, I think so (?), because the main thread runs as STA.
The timer is stopped and disposed when the form closes (Form.Closing event). Do you think it is a problem, that the form is closed from the main thread or that the main thread manipulates the progress-value in the progress-bar form?
|
|
|
|