|
Forgot to mention, when a button's function changes, it is polite to reflect that in its Text.
Helps preventing user confusion.
[ADDED]Still doesn't need an if, the ?: operator is great for such things.[/ADDED]
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
please i need an advice on how i can learn this language very fast. i have some knowledge of c programming and c++. can i learn more myself just by reading. thanks
|
|
|
|
|
Hi,
yes, you can learn the basics of any language from a tutorial book. Go to the bookstore, look at a couple of C# books and buy the one or two that you like most. Work your way through the initial chapters and try a few things on a PC to make it sink in. Skip specialized chapters you don't yet need (databases, networking, ...).
Then read some of the excellent articles here on CP.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Best piece of advice I've seen in a while. 5'ed.
|
|
|
|
|
You have been given an excelent piece of advice from Luc; a man very well respected on this forum. All I can add is that you should take it!
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
I can't agree with the one-voter that hit you
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
FWIW: I have seen that sig before, WNW
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Luc Pattyn wrote: I have seen that sig before, WNW
Can't be mehim! He was a Brit, dontcha know, and Hungarian I am.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
I agree with Luc, but I would add - C# has a LOT of gotchas for someone who assumes that it's like C++, it just LOOKS like C++. If you hope to read a couple of articles and then start a C# project, I would say you need to tread with care.
Christian Graus
Driven to the arms of OSX by Vista.
Please read this[ ^] if you don't like the answer I gave to your question.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
|
|
|
|
|
There are some specific differences between C++ and C# that you should be aware of, like for example how the memory management differs. I made a search on MSDN for some article about the differences between C++ and C#, and realised that a lot of the articles in the search result would be relevant.
MSDN: search for C# C++[^]
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
|
While I do not know for sure IIRC a sheet may be created and deleted and still reside in the metadata in excel. Also I think renaming a sheet sometimes left a copy of the original name in the metadata. One of the reasons we avoid Office apps whenever possible.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi, I have just recently been jumped into C# and its all been a nice learning process. Many times I've had thought to ask here some questions but while typing in the question I have come to some ideas or questions that with google I could solve myself, coming into working solution. So now I am asking is this a good practice...
What problem I had:
Multiform MDI desktop application which had a expiring login system based on time from last user activity. Login dialog would be popped only when certain functionality is launched by user activity. When login has expired the application would just disable certain functionality. Reason for this behavior is to have the application work as a "viewer" all the time and require login only when certain "writing operation" would occur.
Generalizing the problem I thought I need object to maintain whole application (class where the entry point is) which would handle all this using class that's designed to handle all login-related functionality.
So, I wrote a "Login" class which is defined in "Program" class. I also wrote new class that inherits System.Windows.Forms.Form and all my forms inherit from this class. This "customForm" class I have all the basic login functionality:
public partial class customForm : Form
{
public event EventHandler<EventArgs> RefreshActivityEvent;
public void LoginInvalidated(object sender, EventArgs e)
{
}
protected virtual void OnRefreshActivity(object source, EventArgs e)
{
EventHandler<EventArgs> handler = RefreshActivityEvent;
if (handler != null)
{
handler(this, e);
}
}
}
public class Login
{
private System.Timers.Timer InvalidationTimer;
public event EventHandler<EventArgs> TimedEvent;
public string foo;
public Login()
{
InvalidationTimer = new System.Timers.Timer();
InvalidationTimer.Interval = 10000;
InvalidationTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
InvalidationTimer.AutoReset = false;
InvalidationTimer.Start();
}
protected virtual void OnTimedEvent(object source, ElapsedEventArgs e)
{
EventHandler<EventArgs> handler = TimedEvent;
if (handler != null)
{
handler(this, e);
}
}
public virtual void Restart()
{
InvalidationTimer.Stop();
InvalidationTimer.Start();
}
}
"Login" class has event to fire when timer triggers.
"customForm" class has event to fire when user activity occurs (to reset the timer).
In "Program" class constructor I add delegates to each of these events:
FirstForm.RefreshActivityEvent += new System.EventHandler<EventArgs>(RefreshActivity);
SecondForm.RefreshActivityEvent += new System.EventHandler<EventArgs>(RefreshActivity);
LoginObject.TimedEvent += new System.EventHandler<EventArgs>(FirstForm.LoginInvalidated);
LoginObject.TimedEvent += new System.EventHandler<EventArgs>(SecondForm.LoginInvalidated);
So, Program.RefreshActivity() will reset the LoginObject's timer. customForm.LoginInvalidated() is method I can overwrite to add "disabling features" code for each form and then call base class LoginInvalidated() method to maintain basic login functionality.
What I achieve with this is when timer reaches end, each form "knows" the login has expired... and when each form have any user activity, the main program knows this (in RefreshActivity method).
As this is the very first time I do anything like this, I would like experienced opinion if this is the "right way" of doing this?
Next step is to make event for login request in customForm class which would fire Login object in the Program object to pop up the login dialog and forward the information of the login status to the form, also firing LoginValidated in order to enable features that require login. But before I proceed in this, I'd like to have the comfort of knowing I am not doing this the "hard way" just because there's a feature I have not yet stumbled on that would be commonly used for something like this.
Sorry for the long post.
|
|
|
|
|
Looks fine to me, except for class names. I would also move the hooking up of LoginObject and form to a separate class. If there is more than one form, I'd also consider storing them in an array instead of individual variables.
And oh, you're firing the TimedEvent from the System.Timers.Timer thread and have hooked up LoginInvalidated method on System.Windows.Form. Unless you're absolutely sure that you're not going to touch any UI objects, you'll have to use Invoke/BeginInvoke[^]
|
|
|
|
|
So you mean my LoginInvalidated method will be running in different thread than my System.Windows.Form object...
Looks like I dug too deep finding implementation to this and it's time to try something else.
Guess if I keep my MDI parent form as the host and run System.Windows.Forms.Timer to tell me about the expiration, I will be running the timer in same message pump and am safe to touch UI elements in the MDI parent and its MDI childs as theyre shown using .Show method?
And, uh, how would you store multiple forms in an array?
(edit)
OR
I could use static class for running the timer and just read its properties to find out the status of login? It would be less fancy though
modified on Thursday, June 4, 2009 2:37 AM
|
|
|
|
|
Raybarg wrote: So you mean my LoginInvalidated method will be running in different thread than my System.Windows.Form objec
Yes.
Raybarg wrote: Guess if I keep my MDI parent form as the host and run System.Windows.Forms.Timer to tell me about the expiration, I will be running the timer in same message pump and am safe to touch UI elements in the MDI parent and its MDI childs as theyre shown using .Show method?
Yes.
Raybarg wrote: And, uh, how would you store multiple forms in an array?
Form []forms = new Form[2];
forms[0] = FirstForm;
forms[1] = SecondForm;
...
or if the number of forms is not fixed, you could use a List <Form> instead.
Raybarg wrote: I could use static class for running the timer and just read its properties to find out the status of login? It would be less fancy though
I'd rather do it the way you're doing right now - firing a TimerExpired event.
|
|
|
|
|
Hi, i have installed mysql connector so that my application can work with mysql database located at a web server.
i imported this
using MySql.Data.MySqlClient;
when i complied the application, it works fine on my computer. however when i sent my friend the application, he got an error saying
cannot load file or assembly "Mysql.data, version 6.0.3.0 culture=neutrel, publickeytoken=c5687fc88969c44d' or one of it dependencies.
must he install sql connector as well to run my application?
|
|
|
|
|
You need to place the dll for the connector in his GAC or in the application bin directory, or install the connector.
|
|
|
|
|
May i know what is GAC?
meaning i have to send the dll and the exe to him?
possible to combine and just send him 1 file?
|
|
|
|
|
GAC = Global Assembler Cache
And yes, you can create an installer project and deliver him a single MSI that will do all of the work.
|
|
|
|
|
Thanks for your help
will google for more info 
|
|
|
|
|
At a minimum, he needs the dll that contains that library, which I am guessing got installed to the GAC, which means that yes, he'll need to install it.
Christian Graus
Driven to the arms of OSX by Vista.
Please read this[ ^] if you don't like the answer I gave to your question.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
|
|
|
|
|
Hey there
I have a richtext editor i've made in C#. It's just about finished. Everything works very well and i love it lol. But there's one thing I don't know how to do yet and that is inside the Program.cs file when I send the file contents of the file that was opened from within a folder in windows explorer to the richtextbox control on Form1 (SPage)... I don't know how to retreive the name of the file using the args... I don't know how to explain it I'm very confused atm... Here's my code, it works beautifully, I just need to be able to grab the filename and pass it to the Tabpage that it creates and set the Text property of the selected tab to the name of the file.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace J.T_Notes
{
static class Program
{
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
if (args.Length >= 1)
{
SPage frm = new SPage();
System.IO.StreamReader myFile = new System.IO.StreamReader(args[0]);
string line = "";
try
{
line = myFile.ReadToEnd();
if (line.Contains(@"{\rtf1"))
{
frm.Tb.Rtf = line;
myFile.Close();
}
else
{
frm.Tb.Text = line;
myFile.Close();
}
}
catch
{
MessageBox.Show("damn... this ain't workin' so good!",
"J.T Notes 3.1");
Application.Restart();
}
Application.Run(frm);
}
else
Application.Run(new SPage());
}
}
}
Does anybody know how to do this and/or have any suggestions or links to a tutorial/article as I am completely lost. Any help would be greatly appreciated! Thanks
regards,
j.t
|
|
|
|
|
IIRC, args[0] is the name of the application itself. Any filenames will be in args[1] and beyond.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thank you for your reply Peter but I am unsure of how to go about using args[1] to retrieve the filename... Can you please explain in a little more detail?
thanks again 
|
|
|
|