Hello all,

At this moment I am stuck at a point in my project on positioning a control.
This is a textbox that must be positioned 20 points under a table. The table and textbox are positioned in a tabcontrol what is positioned in a panel... logic? don't know but it looks right.
The only thing is that my project is maximised at startup and in design mode it is in the smallest position. In design mode the table is small (100 p) and the textbox positioned 20 points down. The table is in runtime appr. 500 p. high. Only at runtime it hides behind the table and I don't know how to get it positioned under the table. Tried the following as a last option nut I really dont know.

private void Logging_Click(object sender, EventArgs e)
        {
              // Logging is Tab - BerichtInput is Textbox - BerichtOverview is table
              BerichtInput.Location = new Point(BerichtOverview.Left + 120, BerichtOverview.ClientSize.Height + 20);
        }

Is there anyone who can help me with this?

Many thanks!

Recommended Answers

All 24 Replies

You have to get the x,y location point of the control above.Then add to the "y" the height of this control and + 20.
In my example, your new Control is my label, and my listBox is your BerichtInput:

int x = listBox1.Location.X;
            int y = listBox1.Location.Y;
            y = y + listBox1.Height + 20;

            label1.Location = new Point(x, y);

so I get get back to your example:

int x = BerichtOverview.Location.X;
int y = BerichtOverview.Locaton.Y + BerichtOverview.Height; 
BerichtInput.Location = new Point(x, (y + 20))

Hope it helps
mitja

Thanks Mitja,

Thought that as an option too and already tried that. But it doesn't seem to work. As you can see I put the Location adjustment in the tab_click control. Am not really sure that is te right place. Maybe it is the best to put such in the form body.?

Marcel

Try to see what you can do with the Anchor property of a control.

Now I finaly understand what you want to do. You want to move the textBox on the tabControl. This is a bit different then. You hav to add textBox on tabControl - on particular tabPage, then set the new position, like that:

private void button1_Click(object sender, EventArgs e)
        {           
            tabControl1.TabPages[0].Controls.Add(textBox1);
            textBox1.Location = new Point(listBox1.Location.X, (listBox1.Location.Y + listBox1.Height) + 20);
        }

hope it helps,
Mitja

Form is build a little different.
- Form has 2 panels.
- on 1 panel there is a button activated tabcontrol.
- 1 tab has a build on table and a textbox positioned under the table.

So this means my tab is the container for table and textbox. Also startpoint o,o is the tab's. The project is at runtime standard maximized but can be minimized till the size I use in design mode. In design mode and minimized the textbox is perfectly situated under the table. Only when maximized the textboxe uses on a way the location references in disign or minimized mode. This is why I need to relocate it. So the textbox needs the real time location of the bottom of the table which is in runtime (max) approximate 500p from 0,0 instead of in runtime (min) 100p.

Already using the achor for panel, tab, table and textbox. This works fine for all controls. As I was explaining, the tab is put on with a click of a button. There is no click action on the tab itself. Therefore tried also the tab_draw, but this is also not the solution.

Hope this clears my previous info.

Marcel

Is it possible to post a picture of the situation? Because to me it is still not totally clear.

LOL - I dont get a thing now... yes, picture please, otherwise we can discuss to infinity :)
Mitja

LOL - I dont get a thing now... yes, picture please, otherwise we can discuss to infinity :)
Mitja

Links to pictures:

Picture Design mode

Picture running

Hope this clears a lott. Put the textbox up front while running to show where it is.

Marcel

He! We even speak the same language I guess!
But a picture says in fact more than a 1000 words.
So you have a Panel a TabControl on it and a TextBox.
Some things I see:
1) Did you have a look at what is called the Z-order of your controls?
2) You could make the TabControl smaller, to make place for the TextBox underneath, if that is causing the problem.
Or perhaps you defined he TextBox before the TabControl?
Let us know.

ddanbe,

Could use some help in my native language anyway :-) Am learning during creation.

But you can see the following in z-order, think thats what you mean.
level 1: Base form with menubar, 4 buttons and 2 panels
level 2: tabcontrol (for now 3 tabs)
level 3: filling the tabs with tables, textboxes, queries etc. depending on its use.

So the problem you see in the runtime pic is what I mean, 2 controls at the same z level that must be positioned under each other. Each tab has its own features and controls must stay in the tabs.

Thought it was quite a challange to start c# with such a project :-) Am learning every second.

Marcel

Seem to have lost my edit button. Was just wondering, put the relocating things in a tab_click event but it must be when the tab is shown. All times with add. So is there an event that says tabpage_build or tabpage_open?

Marcel

What I still don't get is why it gets so big if you run it. Is that a desired behaviour? Seems like you are developing and running your app with different screen resolutions. You can avoid it, but I have to look it up.

I dont understand a think what are you trying to achive ..sorry! The pictures you pasted here are very unclear. There some good reasonable (eng) explanation would be needed again.
ddanbe doesn`t understand it either - as far as I can see.

So, can you please provide us some more reasonble explanation, and some "better" pictures, if possible?
Mitja

Missed your previous post by a hair. To my knowledge, the're no such events.

Updated the picture in runtime with a more clear one.

Try to explain it in basic:
App is desired to start maximized.

When 3rd button from left is clicked the tab "logging" appears. On this tab is a menu strip, a table (mint field) and a text box (white bar) What I want is the textbox positioned under the table because it is meant to fill the table. A short message with a time stamp and caller id so I can build a logging. That is what it is suppost to do. So under that textbox is some space left to line up the caller id's.

In design I kept it that small because I want to know the app at its smallest working view. But maybe its the other way arround? Start large and downsize in runtime?

What I want is the textbox positioned under the table because it is meant to fill the table.

So you want a table filled with textboxes containing logging events? If that is the case then a ListBox or DataGridView would do a better job here.

So, if I am right if you click on the fancy logging button (the "yellow" ) you show the logging tab and it becomes larger right? But a tabcontrol is designed in the way that if you click on the tab (the one marked Logging) the appropriate "window" opens.
Could you send us some code where all this is happening?

Almost, as the app is running maximized, the tab is also maximized and does not maximize on the button click. Maybe the code explains:

To open the tab:

private void OpenLog_Click(object sender, EventArgs e)
        {
            if (HoofdTabs.Visible == true)
            {
                if (HoofdTabs.TabPages.ContainsKey("Logging"))
                {
                    this.HoofdTabs.SelectedTab = Logging;
                }
                else
                {
                    this.HoofdTabs.TabPages.Add(this.Logging);
                    HoofdTabs.SelectedIndex = HoofdTabs.TabPages.Count - 1;
                }
            }
            else
            {
                HoofdTabs.Visible = true;
                if (HoofdTabs.TabPages.ContainsKey("Logging"))
                {
                    this.HoofdTabs.SelectedTab = Logging;
                }
                else
                {
                    this.HoofdTabs.TabPages.Add(this.Logging);
                    HoofdTabs.SelectedIndex = HoofdTabs.TabPages.Count - 1;
                }
            }
        }

And to close it:

private void CloseLogging_Click(object sender, EventArgs e)
        {
            this.HoofdTabs.TabPages.Remove(this.Logging);
            if (HoofdTabs.TabCount < 1)  // selecteer het actieve tabblad
            {
                HoofdTabs.Visible = false;
            }
        }

Note the HoofdTabs.Visible is set to false at startup, right under initialize component. Like this:

HoofdTabs.Visible = false;
            this.HoofdTabs.TabPages.Remove(this.Logging);

Is HoofdTabs the control I see in your designer?
The one with the tabs | TelefoonLijst | Logging | Apparatuur | ?
Or you are making your life extremely complicated, or I still don't get what your intentions really are. I'm just a mere mortal :icon_confused:

You're correct ddanbe, the control HoofdTabs is the main tab control. Thats the one with TelefoonLijst Logging and Apparatuur.
Don't see it as complicated but as functional and foreall a challange :-).
I just want every tab to be shown separate or as a group as more buttons are clicked. So only the tabs that are used are on the desktop.

But, with all this explaining above, how can I put, what I originally started this thread for, the textbox under the table? Any new ideas?

It just so happens I'm busy with a simple application.
Just a Form, no Menustrip, a TabControl with 2 tabs.
The TabControl fills my form completely, but not at the bottom of my form.
Here I left some place for some buttons, or even a textbox if I needed one.
Perhaps this can help you out?
I have it not here at hand, but if the above is not clear I will send you a picture of it.

Thanks ddanbe,

Sure think this can be helpfull. Please send the picture.
In basic I have the same, only within the tabcontrol. Just want to know how you position your controls under the tabcontrol.

Got some new developments. Put the location code in the click event to open the tab.
Now it repositiones the textbox (and a guiding text) when the form is minimized and maximized after very first clicking the logging open button.

1 It opens in the wrong position (form maximized)
2 click logging button: goes to the right maximized position (form max)
3 minimize form: textbox stays in maximized position
4 click logging button: goes to the right minimized position (form min)

Need to find a way to set it in the right position at opening...so thats the very first click of logging button and after minimizing... Anybody suggestions?

BTW, used this code:

private void OpenLog_Click(object sender, EventArgs e)
        {
            int offsetx = 124;
            int offsety = 40;
            int newx = BerichtOverview.Left + offsetx;
            int newy = BerichtOverview.ClientSize.Height + offsety;

            if (HoofdTabs.Visible == true)
            {
                if (HoofdTabs.TabPages.ContainsKey("Logging"))
                {
                    this.HoofdTabs.SelectedTab = Logging;
                    BerichtInput.Location = new Point(newx, newy);
                    BerichtTxt.Location = new Point(50, newy + 2);
                }
                else
                {
                    this.HoofdTabs.TabPages.Add(this.Logging);
                    HoofdTabs.SelectedIndex = HoofdTabs.TabPages.Count - 1;
                    BerichtInput.Location = new Point(newx, newy);
                    BerichtTxt.Location = new Point(50, newy + 2);
                }
            }
            else
            {
                HoofdTabs.Visible = true;
                if (HoofdTabs.TabPages.ContainsKey("Logging"))
                {
                    this.HoofdTabs.SelectedTab = Logging;
                    BerichtInput.Location = new Point(newx, newy);
                    BerichtTxt.Location = new Point(50, newy + 2);
                }
                else
                {
                    this.HoofdTabs.TabPages.Add(this.Logging);
                    HoofdTabs.SelectedIndex = HoofdTabs.TabPages.Count - 1;
                    BerichtInput.Location = new Point(newx, newy);
                    BerichtTxt.Location = new Point(50, newy + 2);
                }
            }

Better late than never.
Here are my pictures. Don't mind the colors ;) , I just fumbled around a bit with the user interface to see it provides something usefull. I first mind about the internal workings. If that is working well I can still add a 100 Mickey Mouses to my user interface if I wanted to.
The background color of my form is fuchsia :icon_cheesygrin: just to point out some things. On the form I have put a TabControl with 2 tabs: "Invoergegevens" and "Output"
I have set the Dock property of the TabControl to Top and did not let it fill the whole form. I have some buttons on the form in the fuchsia area below and as you can see, if I click on the "Output" tab, the buttons (or textboxes etc.) are still there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.