i am using vb.net
i just wanna ask if we can place a picture in a picture box in different places...
for example, we place a picture in the center of a picture box then we place another picture on the left side of the picture box. is it possible??
and also can we use one picture box that can contain more pictures or images on it???
to make it clear, it is a drag and drop senario, first you have to drag a picture from a toolbar for example, then you are to drop it on the picutre box, the problem is, we have to drop more than one picture in the picturebox, so is it really possible?
To my knowledge, this is not possible with the standard .NET picturebox control.
You could, however, create a custom control that would encompass this functionality.
I'm thinking it wouldn't be too complicated to do.
But probably the best way to handle it would be to create your picture box controls programmatically.
EDIT: Found something that might be useful for you, on CodeProject. Its a extended picturebox control, that seems to have multiple pictures in it.
Extended Picturebox
You will need to build all this functionality from scratch no matter which control you're using. You can use Picturebox, Button, Panel and so on, and they'll all provide the same fundemental for building the required functionality. I would suggest that you used a panel/canvas though. And as Jon suggested, subclassing a panel to create a custom control would properably be the best idea.
Inside this custom control, you will need to keep track of which images that have been dragged into the control, which images is affected by several mouse actions such as click, hover and release, and you will need to draw the pictures manually.
Related
I just have it in my mind. And I can't explain it so here it goes.
A system that only uses 1 form?
It have a two panel, left and right.
The left is consist of buttons
Then the right is associated on the buttons and will change whether what button will be clicked.
Any ideas?
My preference is to do this via custom controls, rather than panels... but panels can work too.
There are a number of ways to do this:
Keep all of the controls layered on top of each other, and then set the Visible property to false for controls/panels you don't care about and to true for the Control/Panel that you do
Move the controls you don't care about out of the visible area
Remove/Add the Controls/Panels from Form's controls collection entirely
I think you can also get a TabControl to put the tabs along the left side, with some formatting that looks more like buttons, such that what you want will be handled without needing to write any code to switch layouts
Any of those can work. Whichever option you use, I have two recommendation for controlling layout and making the transitions smooth.
Call SuspendLayout() before making any changes, and then call ResumeLayout() when you're done. This will help avoid stuttering or a partially rendered form.
Look at the TableLayoutPanel Control. This control will allow you to arrange your top-level panels so that they can be resized with proportion. If you also then dock your individual panels, you can quickly build your program so that it resizes correctly.
You can have several panels, one on top of another. Change their visibility, depending on which one you need at a given moment.
Option #2 would be using a vertical tab control (or a tab strip - see another answer there).
Wondering if someone could help me....
I have a small .NET application where I have an Edit button on a main form. When the user clicks the Edit button, I want to popup a small form right next to it (on top of the main form) with a speech balloon tail attached on the side of the form pointing to the Edit button. So it gives the effect of a floating form pushed out from the Edit button.
I don't want the appearance of a normal speech bubble, I want it to look like an actual borderless form (with square corners). It could be a custom control or anything (however, I am not yet familiar with creating my own custom controls), but I need to add Text Controls, Pictures, Label Controls, etc. to this floating form.
Any help would be appreciated.
Thanks
UPDATE
I am trying to create something to this affect:
So imagine the ? being the Edit button and the other being a form with custom controls.
Like this?
To get this behavior:
Select an image which will represent your speech bubble. Put a PictureBox on the form, make it use this image. Place two labels, as above, adjust the font.
Pick your transparency key (color). Your image background and form background need to be set to that. I used black for demo purposes, which is a bad choice if you plan to have any black or text in your speech bubble. Set form's TransparencyKey property to this color in designer. More about TransparencyKey on MSDN.
(final step, not shown on the screenshot). Set FormBorderStyle = None.
Also make sure you have other ways to close your bubble, because X will be unavailable.
The final result may look something like the following:
Note: You may notice some drawing artifacts, most images on the internet have smooth borders, and transparency key does not support shades, has to be exact color. If you are fine with these minor artifacts, feel free to leave it at that. Or, edit it to get rough borders. Or find another one that better suits your needs.
In VB6 I have been using pictureboxes as containers a lot.
For example I put 5 pictureboxes onto a form, and as soon as the user clicked the "Next" button, I brought the next picturebox into the foreground.
This has been extremely convenient.
Now I am fighting with doing something similar in VB.NET.
My attempts were not really successful. A picturebox does not really hold my controls, they seem to jump out now and then, and I can not really make out on which picturebox a control is currently located since the picturebox is not opaque as in VB6.
Can somebody please tell me how to do this in a good way in VB.NET?
This sounds like a job for the Panel control
For your issues with panels that you posted a screenshot for. Your panel is within another container, that's why it's displaying strangely. Try clicking the panel and cutting it (ctrl-x) then clicking the form header, and pasting it (ctrl-p). That will ensure it isn't within another control as sometimes that can happen in a way that isn't exactly obvious (like how you can see the control borders in your screenshot).
What is more lightweight control, a label, or a picturebox? (label can contain image too).
I will have a form with 110 icons displayed in separate controls and I'm deciding if I should display them in pictureboxes, or a labels.
In VB6, there was an Imagebox control which was MUCH more lightweight than picturebox. What is the most similar control to Imagebox in VB.NET?
Thanks! :-)
Although I know it's not part of your question, the real problem it seems you are experiencing is the fact that you have 110 icons in a single form. I would take a look at the UI and see if there is a better way to lay it out or design it so you don't have to worry about whether or not to use one component vs the other.
I don't think you can compare them because fundamentally they are so different--VB6 controls versus .net framework controls that is.
Take a look at the class hierarchy in .net and you will see that both picturebox and label derive from the same set of classes.
While I didn't itemize the classes' properties and methods, I would guess that the only difference between a Label and a Picturebox is that there is a text property for a Label box thus alleviating you of rendering your own text if there were no Label control and all you had was a PictureBox.
Both a Label and a PictureBox can be assigned an Image object or work in conjunction with an ImageList. So if all you are looking to do is display images then the PictureBox should be just fine (not to mention the fact that it clearly conveys the control's purpose in life: PictureBox:Icons::Label:Text).
In VisualBasic.Net When I activate a picture box and then draw something on it, it draws and then immediately goes blank. Works fine when I re-draw it, but almost always messes up the first time I draw on it. This has happenned with several different programs, and the help file is no help.
Try setting the DoubleBuffered property
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.doublebuffered.aspx
If that's not it, please provide more info.
Usually, if you're drawing something on a picture box or on another control, you have to take over the OnPaint event, and you're responsible of persisting what you draw on this event.
Thank you Andrew, but no help. I'm using .Net Framework 1.1, which does not offer the DoubleBuffered property... it was new in 2.0.
Not sure what additional info to provide.. the code is 300 lines long. When a button is clicked, the code expands my form, makes two picture boxes visible (one on top of the other (the back one is for some graph labels), and then uses some graphic brushes and pens to draw a graph on the front box. There's some database activity and calculations going on in the background at the same time.
I assume you're using the standard PictureBox component. Do you draw in the Paint-Handler? If not then the PictureBox will just erase your painted stuff next time it's asked to redraw itself (erase background etc.).
Yes, I believe I am using the standard picture box.
By Paint-Handler, I assume you mean a [Control].PaintEvent Handler. No I'm not using an event handler to do the drawing... drawing my chart is not an event in itself, but part of a much larger response to a button click event.
If you are saying that having the drawing code be part of a separate and specific handler can solve my problem, than I guess I could raise an internal event every time I want to redraw the chart. But I Would rather just figure out what is causing the PB to redraw itself without being told to.
If you cannot use the DoubleBuffered than you can HIDE a second picture box. You do the drawing in it and once it's completed you draw back to the VISIBLE one. This way the process of drawing is done on the hidden one and the white/flickering will not be shown.