• Log in or sign up for an account here: https://www.sythe.org/login

Tab help + redisgn forms at runtime.

Michael3455

Active Member
Joined
Sep 11, 2005
Sythe Gold
0
Messages
134
Hello, I'm currently making, what I consider to be, a full featured Webbrowser for my Software Development and Design course and I've ran into a few problems, most of which were easily fixable. However, I've got two I can't work out (Due to laziness on one, and my inability to google properly). Firstly, I can't work out how to do these two tab related things. They are
1a. Figure out which tab is currently selected
1b. Figure out how to create a new tab at runtime and add a webbrowser to it.

Both of those, I think, should be a pretty simple thing. But, alas, I can't figure it out and google hasn't been of much help.

My second problem isn't really a problem yet, but rather a question on how I should tackle the problem. User redesign at runtime. Basically, I want to enable a user to select a 'design mode' where they can drag and drop certain elements of the form (Buttons, tabcontrols, etc) so they're placed where the user would like them. Also, have options for background colours and button styles (I'll be making the buttons myself, so probably not many different types) and other things of that nature.

The way I thought I could do this, is when the 'Design Mode' has been selected I disable all the buttons, texts fields and what not, and have an on Mousedown event. As they drag the mouse, I store the location as a point and then update the position of that object (button or whatever it is).


So, basically I'd just like your opinions on my second problem. Do you think the way I thought of as an efficient and effective way to do it, or is there a better option?

And, for the first one, some simple code would be much appreciated.

EDIT: If I've not been clear enough, just tell me and I'll do my best to remedy the situation. Also, I'm not really lazy or a bad googler, I'm just not sure what exactly to google.
 
Member of the Month Winner
Sythe's 10th Anniversary
you're missing out on the core features of .Net's object orientation. I made a simple sort of webbrowser that opened new tabs at runtime etc. but it was fairly buggy.

Have you tried searching through the MSDN library? Its there as a help source and code referrence, its amazing how much people never use it.

http://www.sythe.org/showthread.php?t=183834 - thats my simple code.
 
Two Factor Authentication User
Browsers like FireFox and Internet Explorer actually use MDI forms with no borders, but to make a MDI tab strip is not easy, but works much better and faster (You can also customize it better).

To use a tab control, what you want to do is make a custom tab page which contains a web browser and a property to expose it. Here is a quick code I wrote in 5 minutes.

Code:
    ''' <summary>
    ''' Returns the web browser in the selected tab.
    ''' </summary>
    Public ReadOnly Property SelectedBrowser() As WebBrowser
        Get
            '' If the tab control has no tab selected it will retur nothing.
            If Me.TabControl1.SelectedTab Is Nothing Then Return Nothing

            '' This now checks if the selected tab is a web tab. If it isn't it returns nothing. If it is, it return its web browser control.
            If TypeOf Me.TabControl1.SelectedTab Is WebTab Then Return CType(Me.TabControl1.SelectedTab, WebTab).Browser Else Return Nothing

        End Get
    End Property

    ''' <summary>
    ''' Adds a new web tab to the tab control.
    ''' </summary>
    Public Sub AddNewTab()
        Me.TabControl1.TabPages.Add(New WebTab)
    End Sub

    ''' <summary>
    ''' A class which places a web browser with a tab control automatically.
    ''' </summary>
    Private Class WebTab
        Inherits TabPage
        Private WithEvents WebBrowser As WebBrowser
        Sub New()
            '' Contructs the browser, set its properties and add it to the tab control.
            Me.WebBrowser = New WebBrowser
            Me.Controls.Add(Me.WebBrowser)
            Me.WebBrowser.Dock = DockStyle.Fill
            Me.WebBrowser.Visible = True
            Me.WebBrowser.GoHome()
        End Sub
        ''' <summary>
        ''' Returns an instance of this controls web browser.
        ''' </summary>
        Public ReadOnly Property Browser() As WebBrowser
            Get
                '' Return the browser control.
                Return Me.WebBrowser
            End Get
        End Property
        Private Sub WebBrowser_DocumentTitleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles WebBrowser.DocumentTitleChanged
            '' Set the tabs title to the web pages title automatically.
            Me.Text = Me.Browser.DocumentTitle
        End Sub
    End Class
This code is very basic, and will require a lot more work if you want it to actually be any good.
 
Thanks very much for the code, Flaming Idiots. It looks very helpful and not so complicated that it's above me :D

And yeah, I've got around five weeks to do this assignment so I'm just trying to get a basic webbrowser up and running now, then extend and do all sort of other things to it in the following weeks.

Swan: I generally try searching through MSDN and google extensively before asking questions, but in this case I wasn't able to come up with a likely search term, hence why I came here.
When I arrive home from school, I'll have alooky at your source code! It sounds like it could be very beneficial!
 
Thanks for the offer, but the section 'Web Browser' is pretty simple. However, it showed me how to make a Progress Bar. So that's one less thing to work out :D :D

Oh well. I'll get started on the browser soon, but not really worry about the design. I'd rather chuck together something that looks horrible and work out the kinks of it all, and then redesign it. :D Hopefully I can work everything out alright.
 
well i can help you out alot with the webbrowser so just ask me and ill hlep you
 
Browsers like FireFox and Internet Explorer actually use MDI forms with no borders, but to make a MDI tab strip is not easy, but works much better and faster (You can also customize it better).

To use a tab control, what you want to do is make a custom tab page which contains a web browser and a property to expose it. Here is a quick code I wrote in 5 minutes.

Code:
    ''' <summary>
    ''' Returns the web browser in the selected tab.
    ''' </summary>
    Public ReadOnly Property SelectedBrowser() As WebBrowser
        Get
            '' If the tab control has no tab selected it will retur nothing.
            If Me.TabControl1.SelectedTab Is Nothing Then Return Nothing

            '' This now checks if the selected tab is a web tab. If it isn't it returns nothing. If it is, it return its web browser control.
            If TypeOf Me.TabControl1.SelectedTab Is WebTab Then Return CType(Me.TabControl1.SelectedTab, WebTab).Browser Else Return Nothing

        End Get
    End Property

    ''' <summary>
    ''' Adds a new web tab to the tab control.
    ''' </summary>
    Public Sub AddNewTab()
        Me.TabControl1.TabPages.Add(New WebTab)
    End Sub

    ''' <summary>
    ''' A class which places a web browser with a tab control automatically.
    ''' </summary>
    Private Class WebTab
        Inherits TabPage
        Private WithEvents WebBrowser As WebBrowser
        Sub New()
            '' Contructs the browser, set its properties and add it to the tab control.
            Me.WebBrowser = New WebBrowser
            Me.Controls.Add(Me.WebBrowser)
            Me.WebBrowser.Dock = DockStyle.Fill
            Me.WebBrowser.Visible = True
            Me.WebBrowser.GoHome()
        End Sub
        ''' <summary>
        ''' Returns an instance of this controls web browser.
        ''' </summary>
        Public ReadOnly Property Browser() As WebBrowser
            Get
                '' Return the browser control.
                Return Me.WebBrowser
            End Get
        End Property
        Private Sub WebBrowser_DocumentTitleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles WebBrowser.DocumentTitleChanged
            '' Set the tabs title to the web pages title automatically.
            Me.Text = Me.Browser.DocumentTitle
        End Sub
    End Class
This code is very basic, and will require a lot more work if you want it to actually be any good.


umm, how would u navigate the tabs? [solved]
 
Hey, I've finially started work on the project now (Wasn't going to spend my weekend on a project I'm not totally interested in) and have utilised your code nicely, Flaming Idiots! Thanks again for it. I was just wondering if you'd feel comfortable if I used kept using it in my project. My teacher says it's perfectly fine for me to use others peoples codes, as long as I reference it somewhere in the program (Credits) and also in the documentation that I hand to him.

Also, my homepage (A forum that I Role-Playing forum I frequent), when it loads, returns a script error. Now, I don't get that when I load it up in IE or FireFox, just the one I'm making now. Now, i think I know the reason for this, but I'm not 100% sure. But anyway, when using the browser control, it has something disabled which stops minor error messages from popping up. I'm pretty sure that's what I read. So, how would I go about disabling that? ((Again, i don't know what to search for so I can't really search google. but I'll try)).
 
duelarena.gg
Back
Top