How to select from winforms app - winforms

i created this winforms app and i have text results being displayed in a MessageBox. I came to copy my results only to realize i cannot copy from a MessageBox. what can i use that will enable me to come from or should i just save my results into a file and copy from that?
MessageBox.Show(theStringBuilder.ToString());
I tried a listbox:
Results_lst.Items.Add(theStringBuilder.ToString());
Also a label:
Results_lbl.Text = theStringBuilder.ToString();

You can always roll your custom MessageBox. You can add copy to clipboard option to your MessageBox to keep it simple.
Also
you can copy text to clipboard everytime you show a messagebox.
var msg = theStringBuilder.ToString());
Clipboard.SetText(msg);
MessageBox.Show(msg);

Related

WPF GUI in Powershell - Textbox not being updated until the end of execution

Im creating a simple powershell GUI using WPF like this one...
WPF GUI to powershell
The problem is that the textbox where i show logs is not being updated while the powershell script is executing some commands.
The same function that updates the text of the textbox also logs to standard output, but the messages are shown in the stdout immediately whereas the ones on the textbox are not shown until the end.
$MyTextbox.AddText($LogsLine) -> Not shown until the end
Write-Host ($LogsLine) -> Shown immediately
Is there any way to refresh the textbox after updating its "text" value?
Thanks!
I have tried looking for methods of the textbox or the form itself but i do not find a refresh function.

How to Open document in UserControl using Process.Start()

Currently I have used Process.Start(documentUrl) in the WPF application
to open document.It opens document in a new window.I have one user
control.That User Control is displayed in one of the Dockpanel of the
main window.So when I select some document I want to open that
document in that User control.Is it possible?
I have also used WebBrowser inside the User Control but since it is
not a WPF control.It is displayed in the top layer.Due to which all
the PopUp are displayed behind that User control.So WebBrowser is of
no use to me.
Kindly suggest any alternative.
Hi you should have googled your issue first before asking here.
However here are few links for you. It seems you are looking for Flow Document control.
http://msdn.microsoft.com/en-us/library/ms748388%28v=vs.110%29.aspx
http://www.codeproject.com/Articles/37368/WPF-Flow-Document-For-Beginners

Drag and drop a file into application window using WPF and data binding

I'd like to be able to drag and drop a file (e.g. from Desktop or Explorer) right into the main window of a WPF application.
I also want no code behind, i.e. I want to use data binding.
So far I tested the "gong-wpf-dragdrop" which doesn't seem to support drag targets outside the application.
I could drop a file to the main window and the drag and drop events fired - but the data was empty (dragged a non-empty text file).
EDIT: gong-wpf-dragdrop works (after a small fix) and the problem also occurred when using code behind.
So the complete solution was to use gong wpf (github) and the solution presented by Omribitan.
have you tried GetFileDropList method? you can retreive it from the e.Data in the Drop event.
Something like:
string filename = (string)((DataObject)e.Data).GetFileDropList()[0];

how can I get selected text

I wonder how can I get selected text. (usually done by mouse dragging or shift + arrow on text)
From notepad, word, Internet explorer addressbar, etc.
sending WM_GETTEXT just copy caption, and unable to copy selected text while I rename file name on file explorer.
So, I am considering simulating Ctrl+C. but simulating key strokes seems not a good idea. because it will make side effects.(in case Ctrl+C assigned to other functionality)
I tried following code, wishing copy currently selected text into clipboard
OpenClipboard(0);
EmptyClipboard();
SetClipboardData(CF_TEXT,0);
CloseClipboard();
but no luck, it just emptyclipboard.
how can I copy currently selected text?
(simulating Ctrl+c with no unpredictable effect)
thanks!
(my environments are Windows 7, C programming language, winapi)
I'm not sure if there is a general answer because the various applications you mentioned use different window classes.
For Notepad in particular: The display area seems to be a simple EDIT control. You can use the EM_GETSEL message to retrieve the begin and end of selected text, then use WM_GETTEXT to get the complete text. Do not use GetWindowText because it does not work with windows of another process.
In general, you can try using the WM_COPY message. This should place the text in the clipboard. However, the result depends on how that message handler is implemented in the other application.
You are setting the clipboard using SetClipboardData(CF_TEXT, 0) -- MSDN Doc says that if the second parameter is NULL, the window must process the WM_RENDERFORMAT and WM_RENDERALLFORMATS messages; the same article has a comment on how to allocate Global memory, fill it with the required text and pass it on to SetClipboardData().

Generating output in a Windows Form App

I am working on a windows form app like most development it is usually useful to see output. I am wondering what methods you use to see output in a windows form app.
PS. I am new to visual studio in general.
You can set some Labels around and display text on them:
Label.Text = "Some Text";
And DataGridView controls for information from tables, and for a better insight, you can set breakpoints in your code by clicking the far-left part of your code editing area. When the program reaches to that point it'll stop and you can hover your variables and objects for a better view of their insides...
Oh, and also VS has a "Locals" window when you run your project, that shows all the objects and variables being used and some information about them.
the user interface (a grid or other
controls on a form)
a report (like Crystal)
a file (.txt)
a database table updated

Resources