box1=gtk_box_new(GTK_ORIENTATION_HORIZONTAL,3);
align=gtk_alignment_new(1,0,0,0);
my=gtk_button_new_with_label("HELLO");
gtk_container_add(GTK_CONTAINER(frame),my);
gtk_container_add(GTK_CONTAINER(box1),frame);
gtk_container_add(GTK_CONTAINER(window),box1);
I must write all this code to align a button on the left up of the window or is a easier way.If someone can give me more information about containers of GTK because I understand hard the reference .
Before using Glade I want to see how things works. Sorry about my english.
As the documentation for GtkAlignment notes in Gtk3 there is usually no need to use it as the same effect can be achieved by setting the halign and margin, hexpand properties of the widget that you wish to align.
To have the button in the top left you would set halign and valign to GTK_ALIGN_START.
UPDATE: As noted by jku, GtkHBox, GtkVBox, and GtkTable are now deprecated, and GtkGrid should be used instead. GtkAlignment is also deprecated, and the properties given in the answer by Phillip Wood should be used instead.
I think you meant gtk_alignment_new(0,0,0,0) to align to the left. But without knowing about the other widgets within the window, that looks good to me. That's how you align.
The basic layout containers in GTK are:
GtkFixed which allows widgets to be absolutely positioned.
+----------------------------+
| Widget 3 |
| Widget 2 |
| Widget 1 |
| |
+----------------------------+
GtkHBox allows widgets the be positioned horizontally:
+--------+-----+
| Widget | ... |
+--------+-----+
GtkVBox allows widgets to be positioned vertically:
+--------+
| Widget |
+--------+
| ... |
+--------+
GtkTable allows for a grid or table layout.
+--------+-----+
| Widget | ... |
+--------+-----+
| ... | ... |
+--------+-----+
In addition to those containers, there's also GtkAlignment which allows you to control the alignment of a widget within its allotted space.
GTK+ layout management is a decent tutorial providing working examples of the different layout containers.
Related
I've got a few GroupBoxes containing different number of controls, mostly TextBlocks and TextBoxes, and thereby of different heights.
I generate these GroupBoxes dynamically.
When the WrapPanel is quite narrow you could easily see that the GroupBoxes is of different heights but when the WrapPanel is resized, wider, the layout is rearranged (as it should) but at the same time the GroupBox rearranged gets the same height as the one to its left.
Is there a way to prevent this?
What i want to achieve.
------------ ------------
| BLOCK #1 | | BLOCK #1 |
------------ | |
------------ | |
| BLOCK #2 | | |
| | | |
------------ ------------
Thanks!
//Robert
ScrollViewer can automatically add horizontal/vertical scrollbars for a given element. Now, I have an image wrapped inside zooming/panning control. I want to add scrollbars to the view containing this zooming control. When the image is fully visible, the scrollbars should be invisible. When 10% of the image is visible, the scrollbar thumb should occopy 1/10 of the scrollbar (standard behavior).
The problem here is that I want the ScrollViewer to occupy the area of the zooming control, and adapt its values using the image inside this control. Perhaps this can be done using some kind of binding to the child of the zooming control? Or maybe using two ScrollBar instances instead?
Zoomed out
+----------------+
| |
| +-------+ |
| | image | |
| +-------+ |
| |
+----------------+
Zoomed in
+----------------+
| |
| image sc <- adapting to visibleHeight/imageHeight
| ro
| ll
| |
+---- scroll ----+ <- adapting to visibleWidth/imageWidth
Sigh. Solved it using a ScrollViewer. I had to set the CanContentScroll to True...
I need to display a virtually infinite scrollabe list of interactive widgets and add/remove them as necessary when new data is added or the user scrolls into an uncached area.
A TreeView (as asked about here) is no option, because, I need full Widgets as items (composed of standard widgets with multiple actions etc, but CellRenderer isn't for this)
Worse, I don't know my widgets' height in advance (not much variance though), so using a VBox might cause jumpiness.
Using the scrollbar should still feel as if the list was finite (i.e. updated only after scrolling has finished so the scrollbutton doesn't jump away from your mouse), and when resizing the window and the layout of the windows is updated, the scroll position shouldn't change too much (the focused widget should stay where it is, unless of course the focused widget was scrolled away…).
What's the best way to do this? Maybe even a library that just sends me signals when a new widget needs to be added?
Or could the ListView be coerced to do this in a not-too-nasty way? (i.e. draw on an offscreen buffer, copy that into the cell using CellRenderer, relay mouse/keyboard events to the actual widget?)
If it is a infinity list, then you should not try to achieve anything with a scrollbar - this is only meant for finite lists.
My suggestion is to use an overlay with 2 buttons
+------------+
| UP ARROW |
+------------+
| ITEM N |
| ITEM N+1 |
| ITEM N+2 |
+------------+
| DOWN ARROW |
+------------+
For the list between the buttons, you will probably have to implement a custom container widget yourself.
I suggest to buffer n (>=2) widgets/items in each direction in advance.
Not really related to custom containers, but custom widgets - a starting point
http://zetcode.com/tutorials/cairographicstutorial/customgtkwidget/
http://gnomejournal.org/article/34/writing-a-widget-using-cairo-and-gtk28
http://old.nabble.com/Custom-container-%2B-Child-type-with-interface-td26863728.html
How can I write an windows forms app that displays (multiple) windowless picture boxes, that are always shown 'on top' i.e. always visible?
The idea is for the app to be run at the same time as main application so that the picture boxes 'appear' as though they belong to main application but exist in a separate process. And, preferably the space between the displays remains clickable to the main app e.g.:
---------------------
| -- |
| | | <---------|------App.exe
| -- | |
| -- | |
| | | <- |
| -- |
| |
| | <--- App2.exe
---------------------
Motivation is the picture boxes are used display the output of a 3rd party activex video control that is known to sometimes deadlock. By having it in a separate process the deadlocked video control will not deadlock the entire application.
FormBorderStyle=None and TopMost=true will bring you close. And when showing them Non-Dialog just .Show() they won't stop the ui thread from executing. Also provide some functionality to close them as well. You should make something custom (button) for it because you don't have standard controlbox visible anymore ;) Think of a customcontrol with a picturebox and a little toolbar (close, minimize) underneath it or on top of it.
I am editing custom control in control editor of Visual Studio 2008
My custom control has datagrid view on the left and buttons on the right. I want my control when resized to keep button size constant always and keep them aligned to right border and only my datagrid control to be resized so that horizontal distances between borders and control remained the same. (See illustration below) I remember there was some feature in WinForms and Editor like anchors or other that would me to do that automatically. I just cannot find it in MSVS.
==============================
| **************** *button* |
| * datagridview * *button* |
| * * *button* |
| **************** |
==============================
=================================
| ******************* *button* |
| * datagridview * *button* |
| * * *button* |
| ******************* |
================================
Anchor the buttons right, top. Then anchor the datagrid left, right and top.
That should do it.
Have a look at
Control.Anchor Property
and
Form Anchor