[RESOLVED] Drawing gray rectangle instead of actually resizing
Is there a way to create the effect that I have seen many programs do invloving a gray rectangle? When you drag the corner/side of something to resize it, you see a gray outline of where it WOULD be resized to if you left go of the mouse button.
The reason I ask is because I have an MDI form with a control aligned to one side that I want to make resizable. I added a very narrow picture box aligned to the same side the creates the effect of a re-size bar. The problem is the form flickers a lot when I resize it. I was wondering if there was a way to draw this rectangle ontop of all other windows to show where the control would be resized to if you left go of the mouse button. Any ideas?
Re: Drawing gray rectangle instead of actually resizing
That won't work quite right because I the control is aligned on an MDI form. I need the rectangle to be able to be ontop of any MDI windows (which would mean it can't be drawn ontop of the form). Here is a screen shot...
Re: Drawing gray rectangle instead of actually resizing
My bad. I had a feeling that would happen.
"Right-aligned contorl on MDI parent": It is an MDI form that I am deeling with. For MDI forms you can only put controls directly on the form that are alignable. We are clear on this point, right?
"Resize bar": Okay, I wanted to give the IMPRESSION that that control was resizable, so I added a narrow picture box (30 twips wide) that gives you the W E arrow pointer that makes you think you can resize something if you click and drag.
"MDI Child window": The white area to the left is a maximized MDI child window.
Now, if I use the code you posted, it wouldn't work, because I need the rectangle to be ontop of ALL OF THAT so that you know where you are resizing to without acutally doing the resize before hand.
I am probably asking too much, but I thought it might not be too hard. Here is another screenshot of the desired effect.
Last edited by eyeRmonkey; Oct 12th, 2005 at 12:35 AM.
Re: Drawing gray rectangle instead of actually resizing
Thanks RB. That is really close to what I am looking for, but not quite. I am guessing it isn't really possible to draw a line ontop of all the windows, otherwise the attachemnt project you posted would have done it that way. I might use that though. Great example. Thanks!
Re: Drawing gray rectangle instead of actually resizing
Originally Posted by eyeRmonkey
I am guessing it isn't really possible to draw a line ontop of all the windows, otherwise the attachemnt project you posted would have done it that way.
Oh, it's fully possible to draw lines above all other windows by getting a device context of the desktop. I do that in my Windows Finder Tool (available in the CodeBank). But before you go and look at that I quickly wrote a little class module for you that you might find helpful. It's not 100% perfect since it will draw the line even when you drag it outside of the MDI window but you should be able to adjust that with a little more code.
This is how you use the class:
VB Code:
Private WithEvents oSplitter As CSplitter
Private Sub MDIForm_Load()
Set oSplitter = New CSplitter
Call oSplitter.Init(picSplitter)
End Sub
Private Sub MDIForm_Unload(Cancel As Integer)
oSplitter.Destroy
Set oSplitter = Nothing
End Sub
Private Sub oSplitter_Dropped(ByVal AdjustLeft As Long)
Debug.Print AdjustLeft
End Sub
As you can see you must call the Init method and pass the PictureBox you use as the splitter as an argument. The class will then handle everything when you start dragging the picture box and it will raise the Dropped event when you stop dragging. The Dropped event has one argument called AdjustLeft which is how many pixels (you might need to recalculate that to Twips) away from the origional position you made the drop. This could be a negative value if you drag to the left.
Before you close the Form you should call the Destroy method to be 100% safe.
Edit: Here's a screen shot of how it could look:
Last edited by Joacim Andersson; Oct 12th, 2005 at 01:09 PM.
Re: Drawing gray rectangle instead of actually resizing
One idea I had is that you can add a usercontrol to your project. Set the background to transparent and use it as a sizing box. Here is an example of sizing a picturebox
put a picturebox and usercontrol on your form. Name the usercontrol dragbox and bring it to the front
VB Code:
Option Explicit
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Re: Drawing gray rectangle instead of actually resizing
OK. I've added a Boundaries method which sets how long you can drag the splitter. I also added a StartDragging event in which you can Cancel the dragging if you like, but this is also a good place to set the boundaries.
VB Code:
Private Sub oSplitter_StartDragging(Cancel As Boolean)
'You could set the Cancel argument to True if you do not
'want to allow the resizing.
Call oSplitter.SetBoundaries(MDIForm1.hWnd, 50)
End Sub
The above will set the boundaries to an offset of 50 pixels from the left and right borders of the MDIForm (a pretty good value, but try it out).
I've updated my previous post with the updated class module.
Re: Drawing gray rectangle instead of actually resizing
maybe I don't understand what the monkey is looking for. I was trying to build something like the picture in post #5. I'm not too familiar with MDI forms, so maybe you are saying that there is no way I can put the control on the MIDI form properly?
Re: Drawing gray rectangle instead of actually resizing
That's nice Joacim (it really is ) but somewhat close to that project I've posted but I think eye wants to draw (or mimic if you will) entire rectangle and not single "vertical line" so I'm thinking that multiple pic boxes will do it but it also might create some overhead. What do you think?
Re: Drawing gray rectangle instead of actually resizing
I never looked at the project you posted. However drawing a full rectangle is not a problem you just have to draw the other 3 lines. The class of course needs to know where the "anchor" is, the upper left corner or the upper right corner of the rectangle depending on if your window is attached to the left or right hand side of the MDI Form.
Re: Drawing gray rectangle instead of actually resizing
OK, let's call this the final update... See the attached demo project on how to use the class (I've also added a Color property so you can change the color of the dragging rectangle). The rectangle is optional, and you can still use it with just a line as previous posts show.
Re: Drawing gray rectangle instead of actually resizing
WOW! JA, thats awesome! Thanks a ton. I am not at home right now but I wll definitely take a look at that. You should post that in the code bank. Maybe we can work together to have it offer all the proper options (like offering an option for just vertical OR anchored) and then you can post it in the code bank. I bet it would get a lot of downloads.
Re: Drawing gray rectangle instead of actually resizing
I hate being a perfectionist, but if this wouldn't be too much work it would be awesome if you could get the line to look like this (a pattern instead of a solid color):
Re: Drawing gray rectangle instead of actually resizing
Oh dear... There is just no way of pleasing some people
OK, attached is another version of the class (and a demo project). The demo now shows everything the class can do and you can change the styles of the class using the menu items. You can now either use a (changeble) color or you can use the pattern style, this code now shows how to draw a dotted line (or a line of any pattern).
Even though the demo is entitled MDISplitter, the class can just as well be used with regular Forms. However as it is designed (now) it is only a vertical splitter not a horizontal.
Last edited by Joacim Andersson; Oct 12th, 2005 at 08:58 PM.
Re: Drawing gray rectangle instead of actually resizing
Beautiful wonderful awesome work JA!
I'm working on adding the following:
* Horizontal support
* A focus on a more specific situation (MDI windows and aligned controls on them) instead of a general spliter
* More ease of use and less code needed outside the class.
Re: Drawing gray rectangle instead of actually resizing
Yes, feel free to extend it to your needs (that's what it's for). Personally I will not add any new features to this at the moment since I wrote it as a reply to this thread but I don't need it myself at the moment. However I will post this as it is in the code bank.
Re: Drawing gray rectangle instead of actually resizing
I stayed up way too late last night working on it. I merged your most recent version withe changes I made and I will post it later today (I am at school right now).
Changes I changed/added:
* Added horizontal support
* Added properties (Full Box/Line, Enabled, Width)
* Geared the whole thing towards an MDI form that is using this on a class on an alignable control and a narrow picture box.
* Geared the picturebox towards being places on the MDI form instead of on the picture box.
Still working on:
* Making a Min and Max property that work properly.
* Getting the full box to be drawn horizontally (currently only draws the line)
Last edited by eyeRmonkey; Oct 13th, 2005 at 11:21 AM.
Re: Drawing gray rectangle instead of actually resizing
Okay here is my updated version with all the changes I mentioned in my last couple replies.
Now I am having some problems getting the full box to draw when it is aligned right top or bottom (left works fine). Joacim, I was wondering if you could skim through the code and fix the full box option for right, top and bottom. I would really appriciate it. Everything else works fine as far as I can tell excpet it could use some error checking here and there.
Re: Drawing gray rectangle instead of actually resizing
And once again vbAcc comes to our rescue. I have been trying to put this whole thing into a control for a while, and little did I know it was already done for me (except not in a control...):
Re: Drawing gray rectangle instead of actually resizing
This post has probably been resolved but just in case someone is searching for a code to create a pane splitter, take a look at this code.
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
Re: [RESOLVED] Drawing gray rectangle instead of actually resizing
Thanks Mark!
But the vbAccelerator code I posted in post #29 solved everything with great ease. vbAccelerator rocks. I use code from all over their site now. Its wonderful.