|
Yeah, I saw that but I was attempting to avoid the use of nasty VB namespaces
|
|
|
|
|
J4amieC wrote: nasty VB
If you use the code above you don't need to - it's just that function converted to C#
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)
|
|
|
|
|
J4amieC wrote: As you can see, simple code & easy to port but very different results
No, I can't see; what are the results?
Provided you don't care about Unicode, you could use:
System.Text.Encoding.ASCII.GetBytes()
and
System.Text.Encoding.ASCII.GetString()
You could also access the characters in an unsafe context much like your VB code. Something like:
private unsafe static void
ASCIIize
(
string Subject
)
{
fixed ( char* subject = Subject )
{
int* length = (int*) subject - 1 ;
int index = 0 ;
while ( index < *length )
{
*(subject + index) &= (char) 0x7F ;
index++ ;
}
}
return ;
}
(Though I haven't tested this with the problematic characters.)
|
|
|
|
|
PIEBALDconsult wrote: No, I can't see; what are the results?
The results are cryptic, horrible and mostly non-printable characters which is why I didnt post them. I meant the code was easy enough to port on the face of it.
|
|
|
|
|
Hi.
I have a question on how to create myself a completly new button and use it anywhere i want in my project.
I want to have a button with three pictures. One on click (green as currently selected) one on unavaliable ( red ) and one on avaliable (blue).
For better understanding - i have a miniproject on creating an example of cinema tickets sale. A user selectes in a cinema hall (dont know how its called) a few displayed seats, which are marked blue (as avaliable). and when the operator clicks on it - it turns green and if these tickets are bought the buttons goes red and is unavaliable for further clicking...
i hope its ok explained.
so, i was saying... i could create a few buttons on hand - drag a picturebox. on click - the picture would change its picture to green one and if it was bought - another red picture would be writen. So i want to create a usercontrol with these things.
Is it even possible? or do u have any other solutions for me?
example : Link to a picture[^]
and the number of seats would be generated by user ( 3x4 or 5x1 or etc...)
Força Barça!
modified on Tuesday, November 4, 2008 8:47 AM
|
|
|
|
|
Personally, I would use GDI to draw the seats on the form, and just color/colour them accordingly from the availability and events as you mentioned above.
However, if you prefer to use buttons, you can. You need not create a new button, you can merely change the background color/colour of each button to which ever you require, and then create an event that iterates through each button on the page, stating that if they are clicked and their color/colour is X, set it to Y.
If you insist on a user control, you merely need to create a simple 25x25 pixel user control (or whatever size you want each seat), create an enum value for each state (reserved, un-reserved, etc), and then create a public property to set the "state" of that seat. When the value is changed, you also change the background color/colour of the user control to which ever you require.
There are many methods to achieve what you are after.
|
|
|
|
|
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.
|
|
|
|