Lets say i have created a small game with XNA. Now i can change the windows attributes of the Game by simply obtaining its Form Object by casting & do stuff with it as i can do with normal C# form.
Form MyGameForm = (Form)Form.FromHandle(Window.Handle);
MyGameForm.FormBorderStyle = FormBorderStyle.FixedToolWindow;
now i want that this window(Form) should Always-on-Bottom, complete opposite of Always-on-Top. Meaning the window should stay on the back and never take focus even if i interact with it.
i don't know how to do it but for other stuff in C# we override that function and process whatever we want and return false. For input n text boxes etc. but i don't know how to over ride form focus method or what sets form to on top or bottom or at any index in opened windows on desktop.
no need for it now, i have got the solution, i will simple avoid animating all the stuff for my self and use something that they already built, Windows Dreamscene.
Related
I'm developing in Winforms with a .NET 4 profile in Visual Studio 2010 at Windows' 100% scaling (96dpi) on Windows 10.
As per the advice from this highly rated answer, I set dpiAware to true in the app.manifest file, set the AutoScaleMode of the main Form to Font, and since I have splitContainers in the Form, but they very unfortunately don't have an AutoScaleMode property in the Wysiwyg Designer, I also have to add these lines to the Designer.cs file:
*.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
*.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
This ensures that if the user happens to use Windows in 125%, 150% or even other scaling modes, then the GUI will resize properly, without some components being too small or too big.
Unfortunately, as per the advice of the aforementioned link: "Only the controls in the Controls lists when ResumeLayout at the end of InitializeComponent is called will be auto-scaled", which means I need to put the above two lines in the Designer.cs file. I can't simply put them later in the Form Load event.
Unfortunately, this means that whenever I update or move about a widget/button/label in the Wysiwyg editor, the Designer.cs file is automatically recreated, and I lose my two lines of code above. So I have to keep remembering to put them back in every time I update the GUI in the Wysiwyg editor.
The link also supplies a potential solution to avoid this ugliness by partially avoiding the use of the Wysiwyg editor, and instead creating the splitContainers programmatically in the Load event. I quote: "if you dynamically add controls, then you need to SuspendLayout(); AutoScaleDimensions = new SizeF(6F, 13F); AutoScaleMode = AutoScaleMode.Font; ResumeLayout(); on that control before you add it in".
The problem there is that I have a ton of splitContainer code to move over (such as objects being added to the splitContainers), and it will ruin the look of the Wysiwyg editor (I want to see my splitContainers thank-you-very-much as they are a crucial part of the GUI and have many elements/widgets inside that I also want to see when designing!).
My question is if I can get the best of both worlds: Keep the look of the splitContainers and contents in the Wysiwyg editor, while keeping the functionality of proper scaling by utilizing the two lines of code above (*.AutoScaleMode = ... and *.AutoScaleDimensions = ...) which seemingly must be in the Designer.cs file before *.ResumeLayout() is called.
I am trying to create two user controls in Silverlight using the Windows Phone SDK 7.1. I would like to be able to drag from one control and drop into the other control (or at least receive the event that the drop has occurred).
I am able to give the appearance that the drag is moving the item by using a TranslateTransform. However, I would be interested in knowing whether this can be done by actually moving the element instead of transforming it. Can this be done?
Second, and probably more importantly, how do I get the second control to see the drop event? I've done lots of reading, and no luck with this so far.
FWIW, I am currently using a Grid in each control, but I would be open to changing to a Canvas or other control type.
I am not much aware of windows phone, but we can drag an object from one controller to another controller.(What i did in iOS)
Steps to be followed:
Both controllers should be in same window.
On ManipulationStarted(touches begin) drag the object or item from one controller, Move on another controller
On ManipulationEnded(touches ended) check the dragged object is within the second controller. if Yes, add the object to second controller.
I hope my answer helped you. If it's not useful sorry for that.
I have inherited a large MFC application which contains a CComboBox subclass that overrides OnPaint. Currently it does all its drawing by hand (with lines and rectangles), and renders a combo box that looks decidedly Windows 98-style. However, it otherwise works great and provides a lot of useful custom functionality that we rely on, and rewriting the entire control is probably not an option.
I would like to modernize it so that the OnPaint draws in Aero style where available (falling back to the old code when modern theming is unavailable). I've done this with some other custom controls we have, like buttons, and it works great for our purposes. I know there are some tiny behaviors that it won't get right, like gentle highlights on mouse-hover, but that's not a big deal for this app.
I have access to the CVisualStylesXP ckass, so I've already got the infrastructure to make calls like OpenThemeData, GetThemeColor or DrawThemeBackground pretty easily (via LoadLibrary so we don't force Vista as a min-system). Unfortunately, I don't know the proper sequence of calls to get a nice looking combo box with the theme-appropriate border and drop-down button.
Anyone know what to do here?
Honestly, I don't know why they originally tried to override OnPaint. Is there a good reason? I'm thinking that at least 99% of the time you are just going to want to override the drawing of the items in the ComboBox. For that, you can override DrawItem, MeasureItem, and CompareItem in a derived combo box to get the functionality you want. In that case, the OS will draw the non-user content specific to each OS correctly.
I think you best shot without diving in the depth of xp theming and various system metrics is take a look at this project: http://www.codeproject.com/Articles/2584/AdvComboBox-Version-2-1
Check the OnPaint of the CAdvComboBox class - there is a full implementation of the control repainting including xp theme related issues.
Not sure if it's the same situation - but when I faced this problem (in my case with subclassed CButtons), solving it only required changing the control declaration to a pointer and creating the control dynamically.
Let's assume that your subclassed control is called CComboBoxExt.
Where you had
CComboBoxExt m_cComboBoxExt;
You'll now have
CComboBoxExt* m_pcComboBoxExt;
And on the OnInitDialog of the window where the control is placed, you create it using
m_pcComboBoxExt = new CComboBoxExt();
m_pcComboBoxExt->Create(...)
Since this is now a pointer, don't forget to call DestroyWindow() and delete the pointer on termination.
This solved my particular problem - if your control is declared in the same way, consider giving it a try.
I 'm running into a situation i don't understand and want somebody to enlighten me if possible.
Created a WPF application. For sake of simplicity consider this application to be one window. I put some controls on this window, amongst others there is a TextBox control (let's call it TB).
There is a requirement that this TB must always have the focus (in case someone types something or something is read through the barcode-scanner it should appear there).
I thought implementing this with the help of a timer: every second the focus is transferred to the TB.
Until now everything works fine (as expected).
The weird thing is the following: let's say a new user wants to use this window, so she has to sign in. I thought implementing this with a new Window object (let's call it W2), calling it this way:
W2.ShowDialog();
This W2 window should be modal (bear in mind that the timer still executes).
The crazy thing is that under Windows Vista this works perfectly as expected (this means W2 is modal and the user can to what she should do on W2), BUT on Windows XP as soon as the user wants to type something in a textbox of W2 the focus is set back to TB on the initial Window (as far as i can interpret: this means W2 is not modal!!!? am i right?).
How can i overcome this situation?
Is this the right approach?
Thanks in advance
Make sure to set the Owner property of W2 to your main Window.
From the referenced docs:
When you open a child window by calling ShowDialog, you should also set the Owner property of the child window.
I am not sure this setting-the-focus-back-every-few-seconds is such a good idea. It is always possible that some input will come in the interval between a lost and got focus state (and be lost). Alternative solutions are catching the PreviewKeydown event on the form that the TB resides on and somehow set the output of a barscanner to the TB too.
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.