|
I'm not asking to be spoon fed the code. Just asking if anyone knows the formula.
Yes, I'm also searching with google and I'm already working through some trig tutorials to figure out the math. Now, if you will stop wasting time by posting non-answers, I'll get back to my research.
|
|
|
|
|
Hello everybody,
in my project I have a pictureBox, sitting in one of the panels of a SplitContainer and docking to it in fill mode. The PictureBox loads it's images in zoom mode and is supposed to take the size of the loaded/zoomed image automatically whenever a) the form's size is changed or b) the splitter is moved.
In a first approach to reach this I call
Private Sub FitPictureBox()
If PictureBox1.Image IsNot Nothing Then
Dim thisFrame As Bitmap = PictureBox1.Image
AspectRatio = thisFrame.Width / thisFrame.Height
SplitContainer3.SplitterDistance = PictureBox1.Width / AspectRatio
End If
from the 'resize' event as well as from the 'splitter.moved' event.
Now I'm desperately struggling to make this work, coz the 'resize' event (as well as the layout event) calling 'FitPictureBox' triggers the 'splitter.moved' event again - and I run into a loop i.e. a 'stack overflow' exception. Still I need to consider fitting the PictureBox in both cases.
Could anyone of you please guide me a way out of this dilemma? Did I use the wrong events or is there a better approach at all?
Thank you,
Mick
|
|
|
|
|
Hi, I have also had similar problems in the past with events causing other events to fire. I have found a way around this but really don't think it is the best way, so it will be interesting for me also to see other people's responses.
What I have done in the past is set a global variable and check that variable in the event handlers. So, at the start of your 'resize' event set a variable, say 'Resizing' to True, then in your splitter.moved event, check the state of 'Resizing', if False then do the event. Just remember to set 'Resizing' back to nothing at the end of the 'Resize' event.
Like I said, I don't think this is the best solution, seems a little dirty to me but it works.
|
|
|
|
|
Liqz wrote: so it will be interesting for me also to see other people's responses
Nope - this is exactly the method I use, form level booleans called bLoading sprinkled throughout the app.
|
|
|
|
|
Ah OK fine. I just thought that I might have been missing something native to the .Net framework which does a similar job. But thanks for the reassurance, I shall be more confident in my approach in the future
|
|
|
|
|
If I understand you correctly, the picuterbox is supposed to fit itself to the size of the SplitContainer after the container's size is changed (in whatever way).
Can you do something like this?
1. the container size changes
2. measure the size of the container
3. measure the size of the picturebox
4. if the picturebox's size is (already) correct, do nothing; if it is incorrect call your sub (and do whatever else).
Or what Liqz said...
My advice is free, and you may get what you paid for.
|
|
|
|
|
Wow - I didn't expect such quick responses Thank you both for the ideas!
@Liqz: that's exactly what I tried since I posted. Somehow it seems that the events are fired not only once - so when resetting the flag variable (just by chance I had also called it 'resizing') back to FALSE at the end of the 'resize' event, the problem arises again when it fires a second time...
@Johan:
I don't exactly know the sequence of the different events - resizing of the form might trigger the resize event for a main SplitContainer I have in it AND the resize event of a second SplitContainer which then holds the PictureBox. Do you probably know a way how to find out which event exactly fired my sub?
|
|
|
|
|
Liqz's approach finally worked out well for me after changing the last line in my sub to SplitContainer3.SplitterDistance = SplitContainer3.Width / AspectRatio
It seems as if the dependency between the SplitterDistance and the size of the PictureBox set some built-in event-devils free
Thank you both
|
|
|
|
|
You're welcome, glad I could be of assistance
|
|
|
|
|
The following code is probably the most common code on the net for automating IE with Excel.
Sadly when I use it I get an automation error stating "Method Busy of IWebBrowser2 failed" (The Bold Part)...
Can anybody help me out how to tackle this error?
Sub Button1_Click
Set myIE = CreateObject("InternetExplorer.Application") 'New '
Dim myURL As String
Dim strSearch As String
'Set starting URL and search string
myURL = "http://google.com"
strSearch = "Infosys"
'Make IE navigate to the URL and make browser visible
myIE.Navigate myURL
myIE.Visible = True
'Wait for the page to load
Do While myIE.Busy Or myIE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop
'Set IE document into object
Set myDoc = myIE.Document
'Enter search string on form
myDoc.forms(0).q.Value = strSearch
'Submit form
myDoc.f.submit
'Wait for the page to load
Do While myIE.Busy Or myIE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop
'MsgBox myIE.LocationName
End Sub
|
|
|
|
|
Hi,
I am trying to load a word doc and save it into a table.
I have a column for the file document as type image in the table.
when i doubleclick to select the file it throws an exception because the file type .
dim docs as system.drawing.image
me.openfiledialog.showdialog()
docs=system.drawing.bitmap.fromsream(me.openfiledialog.Openfile,true)
me.PicturePictureBox.image=docs
Guide me please
Thanks :
|
|
|
|
|
The error is due to the Word document not being an image file, such as a Bitmap or JPEG. Don't confuss a SQL Image type as a picture. Search Google on BLOBs
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
Thanks for repling..
I agree but I am not getting a good result on the search from google..
the word document is binary type or bites..
the file is from filestream..
so where lies my problem in getting the right type
thanks
|
|
|
|
|
Why are you even bothering with creating an Image object with a Word document?? The Image class is for handling, well, picture, .BMP, .JPG, .PNG files... not Word documents.
After seeing code like this, I'm quite sure you've got a mountain of other things wrong, so without seeing the code that you're using to setup the SQL INSERT operation, it's impossible to tell you where you went wrong.
|
|
|
|
|
Thanks,
let's do away with my initial coding.
what I want to accomplish in a form is to be able to upload .doc, text, rtf, pgf files and save it to a table..
Upload() will load the document from the file path and put the path into a richtextbox and save it in a table.
viewdocumentclick() will read the document in its format.
Hope I am a bit clearer now..
Thanks alot
|
|
|
|
|
All you're doing is saving a stream of bytes to the database, just like saving an image file. Every file is nothing but a stream of bytes.
' This is array is holding the contents of your file.
Dim fileContents() As Byte
.
.
.
myConnection = New SqlConnection(CONNECTION_STRING)
Dim myCommand As New SqlCommand("INSERT INTO someTable (FileData) VALUES (@Image)", myConnection)
Dim myParameter As New SqlParameter("@Image", SqlDbType.Image, fileContents.Length)
myParameter.Value = fileContents
myCommand.Parameters.Add(myParameter)
myConnection.Open()
myCommand.ExecuteNonQuery()
|
|
|
|
|
Thanks again,
I am using Vb.net(Visual Studio) and SqlExpress where I am using Dataset and TableAdapter.
I just need to click on a command to open the directory, select the file and load it or the path of it into the richtextbox and the savecommand_click() save everything..
On read, readcommand_click() read the file in its format and not being able to edit the document.
thanks
|
|
|
|
|
...and...so, what's the question? I just showed you how to save data to an SQL Server. I have no idea what you're asking now...
|
|
|
|
|
Hi Dave,
The question is not actually saving the information. My question is how to open the folder, retrieve .doc, .txt file, like you will do with an image.
thanks
|
|
|
|
|
Wait, wait, wait... You've already got the hard part done, but can't manage the easy part?
You're looking for the OpenFileDialog in the Toolbox. It'll give you the filepath that the user selected. After that, just tell the RichTextBox what the file path is.
What this tells me is that you've been copying 'n pasting code from all over the web looking for something that does what you want it to do. Correct?
|
|
|
|
|
Hi,
back to my very first question, I can get to the folder, when selecting the file, it throws an exception because of image type record..this column should be of image type since on other occasion scanned document will be inserted there.
Hope you understand me now.
thanks alot
|
|
|
|
|
This doesn't make any sense. Are you saying that you want a "scanned image" of the Word, or some other, document, page-by-page??
|
|
|
|
|
The word document can be on a USB to upload or if only a hard copy exists then the hard copy can be scanned to upload.
thanks
|
|
|
|
|
OK, that doesn't answer my question.
|
|
|
|
|
Hi,
here is the cenario:
a form will capture user informations. One richtextbox is for loading a grievance letter which can be a soft copy or a hard copy. if it is a hard copy, it will be first scanned and placed in a folder. Then the application will load it from the folder.
if it is a soft copy, meaning from a USB Flash drive, the app will get it from there.
Hope I am clearer now
thanks
|
|
|
|