|
i just get an "IndexOutOfRangeException" occuring. Im using Borland C# if thats any help?
|
|
|
|
|
Gavin Coates wrote:
i just get an "IndexOutOfRangeException" occuring
Every exeptions have a Message property, which is string contained a error string.
Gavin Coates wrote:
Borland C#
Oh, I don't know about that. I haven't seen anybody use it here.
Mazy
No sig. available now.
|
|
|
|
|
error is:
"Index was outside the bounds of the array"
|
|
|
|
|
Try
private void btnDelTheListBoxItem_Click(object sender, System.EventArgs e)
{
if(TheListBox.SelectedItem != null)
{
for(int i = 0; i < TheListBox.Items.Count; i++)
{
if(TheListBox.SelectedItem.Equals(TheListBox.Items[i]))
{
TheListBox.Items.RemoveAt(i);
i = TheListBox.Items.Count;
}
}
}
}
This will work
|
|
|
|
|
ggthanks thomasa.
I tried the code above, but again i get exactly the same results! I can delete any item in the listbox no problems, but when i try to delete the first item, it deletes, but causes an IndexOutOfRangeException!!
I tried creating a whole new project with just a listbox, textbox add and delete button, and it worked perfectly, no errors at all. It just causes problems in my current project!!!
Please help!
|
|
|
|
|
Strange.
You should sett up some breakpoints and find out what index the first Item in your listbox has. It should have index 0.
It might be that you add the item to your listbox in a special way?
I use:
TheListBox.Items.Add("Some text");
|
|
|
|
|
What is the most efficient way to wait for a worker thread to complete. I'm making a file sending program and I want to only send one file at a time (i.e. wait for the previous send to finish), but I want the user thread to keep processing messages because I have status indicators and other options that need to be available while sending.
|
|
|
|
|
Sounds like what you want is one dedicated thread that sits idle in an infinite loop waiting for files to send. Each send request would be enqueued into a blocking queue. The dedicated thread wakes up when an item is available in the queue and processes it accordingly.
|
|
|
|
|
Thanks for the reply,
I was thinking too hard, I solved the problem with a single boolean value that I set when I begin and end a send thread, the user thread just check the value of the boolean...somtimes its too easy to see.
|
|
|
|
|
You should look at invoking delegates asynchronously as well: Including Asynchronous Calls[^]. Might help solve the problem another way, even though I see you have solved it using state (just make sure you synchronize access to that state using a Monitor - ala the lock keyword if you like - against a static object or something similar).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hello!
I have a combobox with autocomplete.
This combobox is linked to a field of a database.
I want to do this and I don't know how:
When I choose an item of the combobox to display in a form automatically
the information of that field.
I've made the form and I linked the controls to database using Bindings.
I use OleDb.
Please help me!
Thank YOU!
|
|
|
|
|
Hi, I've just spent weeks making a huge 'wizard' type form for a client and then they phone me today and tell me they want it as a windows form because its costing them too much money entering the data on the internet
What I really want is a utility for converting web forms to windows forms but since I realise this may not exist can anyone offer me any tips on how to convert it.
What I really need is longhorn here now and XAML.
tia
|
|
|
|
|
|
Hi Colin,
Unfortunatley we got the money up front, which seemed like a good idea at the time because it was good money
I can convert most of the form fields to their windows equivalent with a find and replace and most of the form logic is well encapsulated. The only real problem is then I've got to position all the form fields, actucally that is a nightmare because theres over a 100 textboxes and groups of radio buttons etc etc.
Cheers.
|
|
|
|
|
If you get REALLY (and I mean REALLY) desperate, you could host your ASP.NET solution on each machine .
I'd look at it as a learning opportunity, and a chance to do a UI exactly how you want it .
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
Actually thats a very good idea, I remember hearing something about 'Cassini' and hosting asp.net runtime in a windows form.
Im just worried thats theres some big gotcha that will bring the whole idea to a halt.
Has anybody had any success with that approach.
Kentamanos wrote:
I'd look at it as a learning opportunity
LOL, its true, you do learn more on 'nightmare' projects, whatever doesn't kill me makes me stronger and all that
Thanks.
|
|
|
|
|
I am getting a weird problem with the tabpage here is a step by step account of how to reproduce my problem
1) add a tabcontrol and then a tabpage to a form
2) add a custom contorl to the tabpage (a normal control eg label will work as well but i am using a custom control)
3) add functionality that allows you to drag the control/label (i just use the controls mousedown to start DoDragDrop, and then use the drag_enter/move events of the tabpage to make it drag)
4) now set a background image, some big image say 1mb and 1024x768 and drag the contorl/label, you should see that it is slow to paint the control when dragging
HOW CAN I MAKE THE PAINTING SMOOTH?
I have tried double buffer overriding onpaintbackground etc.. but that is not the solution as if i add my control to a panel and then set the panels backgroundimage to a large image the painting is smooth!!!! So the panel does something to make painting smooth that the tabpage does not. The solution i have come across is detailed below however it has a weird problem which i will list below. For now use the following steps to produce my problem
Start a new project
1) inherit from tabpage and produce a custom tabpage class with the code below
public class MyTab : TabPage
{
public Image imagex;
public MyTab()
{
}
protected override void OnPaint(PaintEventArgs e)
{
if(imagex!=null)
{
e.Graphics.DrawImageUnscaled(imagex, 0, 0, imagex.Width, imagex.Height);
}
base.OnPaint (e);
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
base.OnPaintBackground (pevent);
}
}
2) add tabcontrol to form and add the inherited tabpage to it
3) add user control to tabpage then add functionality to drag the control
4) make an Image object in the and set it to a large image in the form class name it LARGE_IMAGE
e.g. Image LARGE_IMAGE = Image.FromFile(@"C:\image.jpg");
5) add 4 buttons to the form which the following in their click events
Button 1
========
tabpage.imagex = LARGE_IMAGE;
Button 2
========
tabpage.imagex = null;
Button 3
========
tabpage.BackGroundImage = LARGE_IMAGE;
Button 4
========
tabpage.BackGroundImage = null;
6) OK now that everythings ready we can begin the test! If you press Button 1 you will see that when you drag the control the image appears underneath it however the painting isnt very smooth but is smoother than in the first example above where you set the backgroundimage. Now if you press Button 2 so the tabpage.imagex is set to null. painting should be smooth again as no background is set. (Forget about the backimage getting erased and painting when u move the control i understand why that is happening that is not the Problem).
Now press Button 3 to set the tabpage's backgroundimage and drag the control around it is slow to paint now press button 4 to set the backgroundimage to null. OK THIS IS THE WEIRD PART, Press Button 1 and tabpage.imagex should paint SMOOTH!!!!! IT is fine now.
I cant understand why this happens? It only paints smooth after setting and unsetting the tabpage's backgroundimage. I have tried doing the following
tabpage.BackGroundImage = LARGE_IMAGE;
tabpage.BackGroundImage = null;
tabpage.imagex = LARGE_IMAGE;
in the constructor of the inherited tabpage but that does not make it smooth, i have added the 3 lines of code to a seperate button again to no change. It seems i have to add the code to different buttons only then will it work!!! WIERD.
Please please can anyone shed any light on this situation? I want smooth painting on the tabpage with out pressing mulitples buttons LOL
|
|
|
|
|
Maybe if you active the DoubleBuffer (one buffer for display the actual paint, and one buffer for the next paint), you paint'll be more smooth. You can activate this Style with:
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
The Control Style UserPaint, and WmPaint are need them for DoubleBuffer.
----
hxxbin
|
|
|
|
|
I'm trying to draw a rectangle around a button that is placed on a panel
with the code:
protected Graphics grfx = null;
private void DrawScanArea(Button aButton)
{
grfx = thePanel.CreateGraphics();
Pen pen = new Pen(Color.White, 5);
grfx.DrawRectangle(pen,aButton.ClientRectangle);
}
Why won't this work?
Thanks
Thomas
|
|
|
|
|
First, never store a Graphics object and always call Dipose on it when you're finished.
Second, using the ClientRectangle of the Button means that the rectangle will be within the Button , which maintains its own state. Drawing a rectangle within said bounds won't be visible. Instead you must inflate the rectangle (you can use Rectangle.Inflate ) by the size of the pen (5, in your example).
You'll also want to do this in the override for OnPaint in your Panel -derived class (or in the Paint event if from another - possibly container - class. Painting this rectangle once will work (if you take into account what I mentioned above) but once the surface requires repainting it won't show up (and only part of it - the invalidated part - will disappear if the whole surface doesn't need repainting). So, in DrawScanArea(Button button) instead set a value to signify that the border should be painted (like a non empty rectangle which you would have to store anyway) and in OnPaint check that state and draw the border if necessary.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Sorry but I realy don't seem to understand the OnPaint event or something, couse I don't get the rectangle to show.
I have a Main class, I've created my own panel class(MyPanel) and added it to the Main form.
On the panel I want to draw the rectangle.(The rectangle shall only be visable for a short period before it will be drawn at a different position)
If I in the MyPanel class add:
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
}
In my Main class i have:
private void DrawScanArea(Rectangle rect)
{
}
Should i create a System.Windows.Forms.PaintEventArgs in my Main class to call up the OnPaint(...) in the panel class?(well I can't since it is protected), so how will it be called up? I would asume it happens when I call the line: grfx.DrawRectangle(pen,rect); in DrawScanArea(Rectangle rect)
, or should the grfx.DrawRectangle(pen,rect);, be placed in the OnPaint(..) in MyPanel class?
My lack of understanding annoys me...
Thanks
Thomas
|
|
|
|
|
First, OnPaint is not an event, it's a method that corresponds to the Paint event. You override OnPaint in a class that derives from another control when you want to control the painting from within that class. You have the Paint event when you want to control the painting from another class. The base class (Control , actually) will call the virtual OnPaint method along with the PaintEventArgs . You should call the base class's OnPaint which will raise the Paint event and might even do other painting operations specific to the base control:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (this.myStoredRect != Rectangle.Empty)
{
Pen pen = new Pen(Brushes.Black, 5f);
e.Graphics.DrawRectangle(pen, this.myStoredRect);
}
}
private void DrawScanArea(Rectangle rect)
{
this.myStoredRect = rect;
if (rect != Rectangle.Empty)
rect.Inflate(5, 5);
this.Refresh();
} So, call DrawScanArea(myButton.Bounds); when you want the rectangle drawn, or call DrawScanArea(Rectangle.Empty); when don't want the rectangle drawn.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thank you Heath for your respons and it
nearly works:
I added to my Main class:
private void DrawScanArea(MyButtonLib.MyButton btnRect)
{
Rectangle rect = new Rectangle(btnRect.Location, btnRect.Size);
ThePanel.StoredRect = rect;
ThePanel.StoredRect.Inflate(5, 5);
this.Refresh();
}
To my panel class:
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint(e);
if (rStoredRect != Rectangle.Empty)
{
Pen pen = new Pen(Brushes.Blue, 5f);
e.Graphics.DrawRectangle(pen, rStoredRect);
}
}
The problem is that the button hides the rectangle(it paints the button over)
I've tryed to put the OnPaint(..) in my Main class, and the ofcourse the panel hids the rectangle.
I tryed to put it in my button class:
private Rectangle scnaRect = Rectangle.Empty;
public void DrawScanArea(Rectangle rect)
{
scnaRect = rect;
scnaRect.Inflate(5, 5);
this.Refresh();
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint(e);
if (scnaRect != Rectangle.Empty)
{
Pen pen = new Pen(Brushes.Blue, 5f);
e.Graphics.DrawRectangle(pen, scnaRect);
}
}
But it won't draw the rectangel at all.
What to do?
Thanks
Thomas
|
|
|
|
|
It works if I in my button class insted:
public void DrawScanArea(Rectangle rect)
{
scnaRect = rect;
scnaRect.X = 0;
scnaRect.Y = 0;
this.Refresh();
}
but then it only show inside the button.
|
|
|
|
|
You're original response stated that you wanted the rectangle drawn around the button. If you would've stated your intentions correctly, I could have given you a good idea of what to do the first time. You also could've used a number of methods from the ControlPaint class in System.Windows.Forms , but for your needs as stated originally I knew this wouldn't work for you.
In any case, you must understand how painting works and how client coordinates are calculated. When you put the painting code in your main form (assuming your Panel wasn't docked), the coordinates where in the client-space of the form, not the panel. Client coordinates are calculated in terms of the container. A Form is a container, just as a Panel is a container. Also, if a Controls handles it's own painting, the painting effects of the container class are not easily made visible (there's a number of things that must be set correctly) because they have two different HDC s that are managed for each control.
Microsoft MVP, Visual C#
My Articles
|
|
|
|