|
Great. Thanks
But i have another question and i dont want to open a new topic :
How to create a specific number of objects X x Y?
6 buttons in a row in 3 columns (6x3)?
And how to add a diferent action on click for different button?
Im sorry for so many questions, as i dont have so much knowladge in C# and i just started to learn properly and whats the best way to learn than through examples
Thanks again,
Matjaž
Força Barça!
|
|
|
|
|
Unfortunately I'm in a training course at the moment, so I have limited resources to my disposal. If nobody else replies by the time I get home this evening, I will send you some sample code.
[EDIT]
DaveyM69 seems to have beaten me to it.
|
|
|
|
|
you don't really need a button - just derive from Control and have an Availability property, override OnClick to set the availability and OnPaint to do the painting.
A very rough mockup to get you started:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace MyControls
{
public enum Availability
{
Available,
Unavailable,
Selected,
}
public class TriColorButton : Control
{
public event EventHandler AvailabilityChanged;
private Availability availability;
public Availability Availability
{
get { return availability; }
set
{
if (availability != value)
{
availability = value;
OnAvailabilityChanged(EventArgs.Empty);
}
}
}
protected virtual void OnAvailabilityChanged(EventArgs e)
{
Invalidate();
EventHandler handler = AvailabilityChanged;
if (handler != null)
AvailabilityChanged(this, e);
}
protected override void OnClick(EventArgs e)
{
if (availability == Availability.Available)
Availability = Availability.Selected;
else if (availability == Availability.Selected)
Availability = Availability.Available;
base.OnClick(e);
}
protected override void OnPaint(PaintEventArgs e)
{
switch (availability)
{
case Availability.Unavailable:
e.Graphics.FillRectangle(Brushes.Red, e.ClipRectangle);
break;
case Availability.Selected:
e.Graphics.FillRectangle(Brushes.Green, e.ClipRectangle);
break;
default:
e.Graphics.FillRectangle(Brushes.Blue, e.ClipRectangle);
break;
}
base.OnPaint(e);
}
}
}
[edit]forgot the event keyword! [/edit]
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
modified on Tuesday, November 4, 2008 9:59 AM
|
|
|
|
|
I tried browsing for a simplistic threading tutorial / article with no avail, a lot went into to much detail t ha is a little to complex for me right now. All I want to do is launch a form in a seperate thread as my main form is laggy because of a bunch of loops that goes on in it.
Any ideas or suggestions as to what to read to get a basic grip of threading?
|
|
|
|
|
Are the loops used for creating or updating form controls, or just doing other data processing? If not for form controls, then could you put all that work in a separate thread? It might make your main form less "laggy".
Another idea might be to call
Application.DoEvents()
at the end of each loop iteration. I've seen some people prefer to avoid this method, but I've personally used it without much trouble. This should keep your form responsive.
Brandon
|
|
|
|
|
EliottA wrote: All I want to do is launch a form in a seperate thread
You cannot do this. All GUI, including other forms, must be launched on the app's main (GUI) thread. If you try to do this on another thread, it may work one time, but not another, and you'll get strange behaviors in the forms controls and rendering issues.
You put your work on other threads and Invoke functions on the forms to modify the controls for your threaded code. You cannot directly modify controls on threads other than the one that created the control.
|
|
|
|
|
So you're saying instead of attempting to load a form through a new thread, i should put my infinite loop which reprocesses data continuously in a seperate thread? (Take my loop out of the GUI thread?)
|
|
|
|
|
|
hi
Am working on C# 2003 ,what is the function point to EOL End Of Line....i want o read string from textfile each 7 char read alone so i need end of line function>>>>>>
thanx
Amani
|
|
|
|
|
My guess would be to use the ReadLine function. You couldn't find this with a google search, or even using intellisense?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: or even using intellisense?
sorry, but that requires somesense
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Too plain solution, too plain channels for a hacker.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi all,
I need to develop an application that can compare an Excel spreadsheet with some data that I can view on an internal site
My plan was to
-read the data from Excel into a dataset,
-get the data from the site in XML format and
-then compare this.
My question is - do you think this is the best way to solve this? i.e. get the data from Excel into a dataset, get the data in XML format from the site to a dataset, and compare the two?
I'm not even sure that the data I get from the site is in a format that can be compared to the Excel data as the tables aren't the same, so I will probably have to modify it so as to make them in a similar format before comparing
any input appreciated
edit: re-reading this i m not sure its clear:
source 1 :: Excel
source 2 :: Data on an internal site
objective: compare the 2
suggestions: see above
question: best solution
|
|
|
|
|
Hard to say from the info you peovided. maybe you should think of some parsers.
SkyWalker
|
|
|
|
|
Basically i don't need an optimal way to do this as this will run once a week only from a local machine - no particular speed requirements
Let's say that the database info I get from the site is similar to the one I have on Excel, can I just confirm that I can connect to the Excel using ado.net and get the data in a dataset. I will then have an XmlTextReader with raw XML data from the site - convert that into a dataset and compare the two datasets.
Does this plan make sense?
|
|
|
|
|
You have, I guess, the software requirements,so it's entirely up to you to set the approach to solving your problem.
SkyWalker
|
|
|
|
|
Hi,
I have a Windows based application and I'd like to make some validations before running (like license or something)
My question is if I do those validations inside the application main form and it's not successfuly done, I'd like to quit, I'd would prefer a friendly "Not Registered Application" message and then close it than throwing an exception.
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmGuardian());
}
}
public FrmGuardian()
{
if (!validInstall())
this.Close();
using (FrmSplash splash = new FrmSplash())
{
splash.Show();
InitializeComponent();
splash.Close();
}
}
In the current code I get
Cannot access a disposed object.
Object name: 'FrmGuardian'.
Thanks,
Dirso
|
|
|
|
|
Hey
What line causes the exception. And also have you tried doing the validation on form load, see if it still happens?
Let me know if it helps.
Thanks
At university studying Software Engineering - if i say this line to girls i find they won't talk to me
Dan
|
|
|
|
|
You can put the verification either into the Load event handler of your form and do the Close() there, or just put the verification before all the Application.XXX calls in the Main method, this way the form will not be created at all.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi Dirso,
You can put the validation code in your Main method, before you even instantiate your form.
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
That would be the best solution, but I'd like some general solution that would work for Console Applications too.
for example, what If one of my funcional classes can't load because its configuration is missing or if some device is offline... First, I ask if the user wants to try again, but if it quits, I need to shut it down.
Thanks,
Dirso
|
|
|
|
|
Console apps have a Main method too A console app exits when you return from Main .
You could also add a reference to System.Windows.Forms if you want to show a message box or even a form. That would kind of subvert the console format, though.
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
Nick Butler wrote: Console apps have a Main method too Confused A console app exits when you return from Main.
I know... and I haven't thinking about moving my code to other methods than the construtors... I'll give it a try
thanks,
Dirso
|
|
|
|
|
Dirso wrote: public FrmGuardian()
{
if (!validInstall())
this.Close(); // here I tried Application.Exit and Application.ExitThread
using (FrmSplash splash = new FrmSplash())
Exit from the C'tor before executing the remaining code..
if (!validInstall())
{
this.Close();
return;
}
*jaans
|
|
|
|
|