Forcing Arrange in a Custom WPF Canvas - wpf

I'm working on a project that involves creating a custom graphical editor. The graphical editor has multiple tabs, and I want to create a preview function that will show a popup with Bitmap previews of the content of each of the tabs. However, the problem I'm running into is that the content for each of the tabs must be arranged before a proper preview can be generated for it. This means going into each of the tabs to ensure that they're rendered and arranged. Then, and only then, do the previews get properly generated, otherwise the previews have a size of 0x0. Does anybody know how to force an arrange of a content control so that I can get a properly sized preview generated ?

Apparently you can just call the 'Arrange' method directly, but you have to be careful about the rectangle you pass in as a parameter, because it can adversely affect the display of your control if you just want to force the object to draw itself (ie can force it to draw out of the desired position).

Here is a link to MSDN where it discusses the "arrangeOverride" method of a control.
I'm not sure this is what you need, but this method seems to be what you're asking about.
Hope this helps!

Related

Codenameone Detect keyboard showing

Is there a way to add a listener on the Form for when the virtual keyboard shows or dissapears in Codenameone?
The reason is because I want to detect this and recalculate the size of the Form. Currently, the sizeChangedListener does not get called when the keyboard shows, and so some components are hidden from view, as I can't recalculate the sizes of the components.
See Display.getInstance().setVirtualKeyboardListener(...)
You shouldn't do that.
Keyboards resize the UI only on Android and don't have that affect on iOS/Windows. We will probably change that behavior on Android as well so relying on it in that way doesn't make sense.
Size changed is called on the form when running on Android otherwise basic stuff wouldn't work. Notice that you shouldn't rely on it for typical code, if you use scrollable containers properly and the right layout things should automatically rearrange themselves correctly.
I suggest rephrasing the question with a sample of your UI/layout and problems including screenshots. E.g. a common issue is placing a text field within a non-scrollable container so the resize logic can't do anything and it fails by making the text disappear.

GtkColorChooser vs GtkColorSelection

(Jacked straight from my last thread:) Reading through the GTK Book, there are lots of things to clean up when making sure to learn GTK3-focused skills. One is color selection widgets.
First, I'm wondering how GtkColorChooser is supposed to permit alpha choosing. The book just has you gtk_color_selection_set_has_opacity_control (GTK_COLOR_SELECTION (colorsel), TRUE);. There's a similar function for GtkColorChooser, but it doesn't seem to create anything. There's also the show-editor attribute that I flipped to TRUE without seeming to do anything.
Second, is there an equivalent notion to GtkColorSelectionDialog->colorsel for GtkColorChooserDialog? As in, can you access the GtkColorChooser widget from the parent dialog?
EDIT:
This is the source for the dialog creation where I'm missing something. I'm expecting this to show me an alpha-enabled color chooser widget, but it only gives me the regular swatches.
dialog = gtk_color_chooser_dialog_new(title, window);
gtk_color_chooser_dialog_set_use_alpha(GTK_COLOR_CHOOSER(dialog), TRUE);
My only guess is that I'm trying to access the color chooser incorrectly, but I haven't been able to find sufficiently detailed instructions about how to get to the chooser from the dialog.
the GtkColorChooser interface allows choosing the alpha channel by setting the :use-alpha property:
https://developer.gnome.org/gtk3/stable/GtkColorChooser.html#gtk-color-chooser-set-use-alpha
when the :use-alpha property is set, you can select the alpha when creating a new custom color in the editor; a new scale widget will appear at the bottom of the color editor and will let you select the alpha level:
the GtkColorChooserDialog is a GtkDialog with a GtkColorChooserWidget inside the dialog's content area, so you can use gtk_dialog_get_content_area() and then get the first child of the returned GtkBox. this is arguably a layering violation, and should not be needed: GtkColorChooserDialog proxies all the GtkColorChooser methods to its GtkColorChooserWidget, and you should never need to access the widget directly. if you want to keep control of the GtkColorChooserWidget, you should create your own GtkDialog and pack a GtkColorChooserWidget into it yourself. again, I would not recommend doing that unless you want to create your own custom dialog.

WPF Printing large custom control

I'm sorry if this is a duplicate, but I couldn't find anything relating to it.
I'm trying to create an XpsDocument from a custom control that I have. The custom control already defines properties for a header and a footer, along with the body.
The idea is to be able to use that same control (or derivatives of it) as an input to some custom DocumentPaginator that will create a printer-ready version of that "report", with the header and the footer put on every page, and the controls, inside the body, showing in full (I don't want to create a bitmap of the whole control, then scale it and cut it where the page ends).
Any ideas on how I can split the contents of a user control into pages?
Or suggestions on a different way to achieve the printing of the control onto pages?
Thanks a lot in advance
Check of VisualDOcumentPaginator;
http://www.codeproject.com/Articles/164033/WPF-Visual-Print-Component

How do I adjust the size of the dropdown portion of the a combobox with PyQt

I'm creating a program where the width of column needs to be relatively narrow, but when I add a combo box I have to increase the width so that I can read the listings in the drop down. I know that in HTML the drop down adjust to the length of longest entry, in Iron Python you can adjust the drop down width manually, but I can't seem to find any reference to either of these options in PyQt. If I'm missing it in the documentation, a friendly pointer to the right spot would be of great help. Thanks.
The dropdown portion is a component that inherits QAbstractItemView (usually QListView).
It is accessible via the view() getter of the QComboBox. You can play with its sizePolicy to get what you want.
If it is not satisfying, you can even set your own QAbstraItemView to the QComboBox via `setView'.
In Qt a widgets size is usually controlled by its layout. The layout management docs should help. In particular, take a look at QSizePolicy. If you're using designer, you can set these directly as properties, otherwise you'll need to do it in code. The basic layouts example may help as well.

Complex .Net 2.0 Windows Forms control: where to start?

In order to make a convenient UI for an .Net 2.0 Winforms application I am working on, I have need for a control that I'm pretty sure goes beyond the "out of the box" behavior of any standard control. A mock-up of what I'm trying to achieve follows:
Mock up http://www.claware.com/images/temp/mockup.png
Essentially, this part of the application attempts to parse words into syllables from tribal languages (no dictionary to refer to; any and all unicode characters are possible.) By the time the user gets this far, he has already defined the vowels / consonants in his language and some other configuration. There is then an iterative process of (1) the application guesses which syllables exist in the language based on some rules, (2) the user refines the guesses, selecting the correct parsings or manually parsing a word, (3) the application "learns" from the user's feedback and makes smarter guesses, (4) repeat until the data is "good enough" to move on.
The control needs to present each word (the grey headers), then all the syllable break guesses (the white areas with dots separating the parts of words.) There is also a way to manually enter a parsing, which will display a text area and save button (at the bottom of the mockup.) When the user hovers over a guess, the background changes and "accept / reject" buttons appear. Clicking on the accept, or entering a manual parsing, removes the entire word from the list. Clicking the reject button removes just that item.
I'm by no means 100% sold on the formatting I have above, but I think you can get a general idea of the types of formatting and functional control I need. The control will also scroll vertically--there may be thousands of words initially.
My question for you experienced WinForms developers is: where to start? I would really, really like to stay within the .Net core framework and extend an existing control as opposed to a third-party control. (At the risk of starting a religious war: yes, I suffer from NIH-syndrome, but it's a conscious decision based on a lot of quick-fix solutions but long-term problems with 3rd party controls.) Where can I get the most "bang for my bucK" and the least reinventing the wheel? ListView? ListBox? ScrollableControl? Do I need to go all the way back to Control and paint everything manually? I appreciate any help that could be provided!
[Edit] Thanks everyone for the ideas. It seems like the most elegant solution for my purposes is to create a custom control consisting of a FlowLayoutPanel and a VScrollBar. The FlowLayoutPanel can contain instances of the custom controls used for each word. But the FlowLayoutPanel is virtual, i.e. it only contains those instances which are visible (and some "just out of scroll"). The VScrollBar events determine what needs to be loaded. A bit of code to write, but isn't too bad and seems to work well.
I would look at the TableLayoutPanel and FlowLayoutPanel controls. These will let you organize a series of controls with moderate ease in a vertical fashion. I would then create a UserControl that consists of a label and 2 buttons. The UserControl will expose properties like Text and events that are exposed for the button clicks.. For each entry in the list, you will create an instance of the UserControl, assign the text value, and handle the click events. The instance will be placed in the Table/Flow panel in the correct order. Both of those layout panels do allow for inserting items between other items so you can add/remove items from the list dynamically.
Edit:
Given the length of what you are trying to render, I would consider using the DataGridView and do some custom rendering to make it perform how you want it to work. Using the rendering events of the DGV you can merge columns, change background colors (like highlighting the dark gray lines), turn on/off the buttons, and handle changing the grid into edit mode for your rows to allow modification or inserting of new values. This method would easily handle large datasets and you could bind directly to them very easily.
Well, this certainly looks like a candidate for a custom component that you should be creating yourself. You can create this using standard .Net drawing commands along with a text-box, and a regular button control.
Now you want to find out where to start.
Create a Windows Forms Control Library project.
Drop in the textbox and the button control.
The panel drawing code should preferably be done by code. This can be done using the regular GDI+ commands.
Edit:
Here's another idea, and one that I've practically used in my own project with great success.
You could use a web-browser control in the app, and show your data as html. You could update the source of the web-browser control based on the input in the textbox, and clicking on the links in the web browser control will give you the event that you can trap to do some action. Your CSS will work.
I used this technique to build the 'desktop' in an app I made called 'Correct Accounting Software'. People loved the desktop so much that it is one of the best loved features of the app.
Here's how I would do it:
Create a custom control. In this custom control, have a ListBox atop a LinkButton, and when the LinkButton is clicked you can make it give way to a TextBox. The ListBoxes will have the top row unselectable... you can probably get the rest from there. When you get your list of words, fill a Scrollable of some kind with one control for each word:
(foreach String word in words){
myScrollable.add(new MyComponent(word));
}
From there, I'm not sure what you want to do with the boxes or the data, but that's my initial idea on the UI setup.
Use the WebBrowser control and generate the HTML markup into it using DocumentStream or DocumentText.

Resources