I'm wanting my winform to conform to the size of an image I pass to an image box held on my form. When I start the program it looks like this:
Then when I pass an image to my picture box it reshapes to this:
However, what I actually want is for the winform to resemble this. I had to manually drag the window to get it this way:
I'm not entirely sure how I can achieve the third one via code. At the moment this is what i have:
this.Size = new Size(imagePreview.Width, imagePreview.Height);
Is there something else I can do code wise so i always end up with the result in the third picture, no matter what size of the image?
There is one built-in property that could help you - Size Mode. Try it and if this does not suit your needs you can implement your own method for this - click me!
Related
i'm trying to mirror my Richtextbox to another screen in Pictuerbox. actually i did that but my issue is (Lets to make my question clear say that we have 2 screens (Screen A and Screen B).
I want to show the Richtextbox in Screen B. As when i open a start menu in screen A it mustn't be shown in screen B. All i want in my program is to mirror the richtextbox as a control not the whole screen.
is that possible?
I dont know if it works and i dont have time to try it but i think you need to create 2 controls. By the 1st one you check the .textChanged() and when it is triggered you update the second textbox.
Example (pseudo code):
TextboxA;
TextboxB;
If TextboxA.TextChanged()
{
TextboxB.Text() = TextboxA.Text();
}
Maybe there is an better way, but this is the way i should try when i make it for my self. Hope it helps you.
What you describe sound like two over network connected applications. I would suggest to look for a chat network app. There are lots of examples in the net. On one side you will have a server and on the other side a client. Then you transfer your text char by char or word by word over the network.
This is the cursor I want to use. It has a little plus sign below the arrow:
When I try to set the current cursor in my Windows Forms app, I do this (and it works):
Cursor.Current = Cursors.WhateverCursor;
The available cursors can be seen here. Notably, I do not see one like I want.
How can I get that little plus sign cursor?
This is the list again, in case that link dies:
AppStarting
Arrow
Cross
Default
Hand
Help
HSplit
IBeam
No
NoMove2D
NoMoveHoriz
NoMoveVert
PanEast
PanNE
PanNorth
PanNW
PanSE
PanSouth
PanSW
PanWest
SizeAll
SizeNESW
SizeNS
SizeNWSE
SizeWE
UpArrow
VSplit
WaitCursor
The system cursors only get you so far. For more you need to use an external resource..
You should create a proper cursor file (somefile.cur) and then assign it to the current cursor:
Cursor myCursor = new Cursor(yourCursorfile);
Cursor = myCursor;
To create it do use a nice application; I found Greenfish to work OK (although their own icon looks like crap ;-)
Make sure to avoid colors, as the above code won't work with colors, afaik.
Here is an example I used in one of my projects..
If you want to use it for a drag and drop operation (which is generally where this kind of cursor shows up) check out DragDropEffects, I think that's what you're looking for.
So, I'm coding a "game history" that the user enters and that information entered is turned into an image-file that is displayed. It's hard to explain -- just take a look at the mock-sketch I created:
Essentially, what I'm trying to do is have the user click the "Add New" button and the GUI pops up. Inside of the GUI, the user will have a few options of which ICON they used, WIN/LOSS, what type of game it was, and a couple of stats. I'd like everything the user inputs to create a new History Record (an image) with the ICON, WIN, Type, stat1, stat2, stat3 in the pre-defined locations that I've labeled... The problem I'm running into is simply "How do I make my code create a new image based on the information the user has inputted. -- and have a working scrollbar on the side."
I was thinking something along the lines of having a picture-gallery type of a setup that could accommodate the History Records... but I just don't know how to use code to create the image itself from data the user enters.
*Note: I know I can use the text-to-image features from .NET, but the problem is that I have an ICON (image) on the side as well, which makes it complicated. I'm a little lost on how to put everything together. Any would would be MUCH appreciated. Thanks!
I'm a VB guy, so:
Dim tFont As Font = New Font("font name", ...)
Dim tImage As Bitmap = New Bitmap (150, 50)
Using tGraphics As Graphics = Graphics.FromImage(tImage)
tGraphics.DrawImage(...) ' Draw your image/icon at the appropriate place
tGraphics.DrawString(...) ' Draw your text in the appropriate places
End Using
I have a form in an application developed using C#. In that form I have created a graphic shape (a circle). At run-time I want my form also to be of that shape only. That is, I want to display only that graphic and not the form back ground or title bar or anything. I want to display only that graphic. But the thing is I'm not able to shape my form. I have that graphic control as a User-Control which I have added to my form.
I suspect you're trying to make a splash-screen like effect. This isn't terribly hard to do. Here's a good tutorial to get you started.
The trick essentially is to set the transparency key of the form to the color you wish to be transparent (in this case, everything except your circle. Additionally, you need to set the form to be borderless.
As an aside, you might edit your question to add some information about why you want to do this - I am curious what your goal is, in terms of user-experience.
You could also check MSDN for the Region property. You can use System.Drawing objects to draw whatever shape you want then set the forms Region property before its shown and it will take whatever shape you give it...heres a short example:
http://www.vcskicks.com/custom_shape_form_region.php
If you want a circular form you can put the following code in the form load event handler:
System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath();
//this line of code adds an ellipse to the graphics path that inscribes
//the rectangle defined by the form's width and height
myPath.AddEllipse(0,0,this.Width,this.Height);
//creates a new region from the GraphicsPath
Region myRegion = new Region(myPath);
this.Region = myRegion;
and then set the FormBorderStyle property of the form to None.
I have a user-uploaded image pulled from the database that I am resizing smaller to display on a web page that I intend to print. I thought about saving a smaller version when the user uploads it, but since the design of this document hasn't been finalized yet, I was looking for something more dynamic. Also, this document only needs to be printed up once, while the image uploaded is displayed at various places in the app numerous times.
Using javascript to resize it while keeping its proportions, it was printing fine for a while. After adding a margin for styling, the printer started printing the image at its full size. I'm assuming it's the margin. It looks fine on screen but pushes everything off the page on paper.
This led me to look into resizing it on the server, in the C# code, but we use user images uploaded to the database, and I can't seem to find the right time or place in the page life cycle to access and change the width and height. I've tried the various methods on the web using Bitmaps, but they all want a file, when I am using a FileDownloader page as the image url.
Perhaps I'm looking in the wrong place entirely and need to go back to the client. Advice and help is appreciated.
As long as your FileDownloader page returns the proper resized image, it shouldn't matter that you're not point to an actual image.
I'd something like this in your FileDownloader page (pseudo code):
using (Image img = LoadImageFromDatabase())
{
using (Image resized = ResizeImage(img))
{
Response.Clear();
// Set proper headers
using (MemoryStream ms = new MemoryStream())
{
resized.Save(ms); // maybe the function isn't called Save, can't remember a 100%
ms.Seek(0); // Can't remember if this is necessary
Response.BinaryWrite(ms);
}
}
}
Like I mentioned it's highly pseudo code, but it should be straight forward with a Visual Studio open, I just haven't access to it right now, and it's been quite a while since I last used this (since I'm stored the resized images like most other in this question recommends - I do so too, however I realize this is not an option for you)
When you are going to have to resize an image to known constraints, and there's the possibility of having to do that multiple times, I'd always advocate doing the resize once (on upload) and storing the result. Of course, you don't say that you need to retain the original image size, but if you do, then you just have to store the image twice - once original size and once at the resized dimensions.
Once you've done that, you can worry about defining your print layout based on the known dimensions of the resized image, and not have to faff about resizing for each use.
I would suggest converting on upload and possibly saving both images in case you want to let the user click through to the full image. Using this model you only do the conversion once and can render either size image. The GetThumbnailImage() method on the Image class will do what you desire, something like this:
String imageFile = uploadedFileName;
Image baseImage = Image.FromFile(imageFile);
Image thumbImage = baseImage.GetThumbnailImage(300,300,..., ...);
SaveMyImage(baseImage);
SaveMyImage(thumbImage);
Be sure to check the documentation for the parameters to GetThumbnailImage() to verify scaling issues and callback handling.
Could you implement such a process:
User sends an image
Image is opened by a function/routine/script, while the user waits
Image is resized on the fly and saved in the correct location which returns a code for success
User receives a message depending of the return value of the script.
EDIT:
I agree with most of the replies you got here.
If the pictures are stored in a database you need to first make thumbmails for all pictures and put them in the same database, then you need to implement a process to create the thumbmails on the fly when adding new pictures.
Disclaimer: I'm suggesting the open-source library I designed for this purpose. I'm definitely biased, but 4 years and thousands of happy users justify my bias :)
You shouldn't be resizing images inside an .ASPX page, or serving them either. Images should be handled in separate requests by a HttpModule so responsiveness doesn't suffer.
If you have some kind of ID in SQL for each image, you can use the SqlReader VirtualPathProvider to make it accessible via a URL, like /sqlimages/id
Combine that with this free, open-source dynamic image resizing module, and you're set.
You'll simply reference images like this: http://localhost/sqlimages/id?width=300&height=200 from your HTML, and you may not even have to write a line of C#.
If you write your own solution, read these 28 pitfalls you should avoid, so you don't end up crashing the server.
Hope this helps!