|
That's terribly inefficient. The RichTextBox already supports all that - changing the selected font, etc.
As I mentioned before (and you continue to waste performance and memory on such a large solution using the WebBrowser control), you enumerate the IHTMLElement s from the IHTMLDocument2.all collection. When you find the elements you want, concat the text:
string str = string.Empty;
foreach (IHTMLElement2 elem in doc.all)
{
IHTMLInputElement input = elem as IHTMLInputElement;
if (elem != null) str += input.value;
} This is untested, but should give you an idea of how to concat text from text boxes. You should refer to the MSHTML reference to know how else to do things. Anything you can do in scripting you can do with MSHTML and more.
Read the MSHTML Reference[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i want opendialog .i need name of file only no directory of it in filename.
how i do?
|
|
|
|
|
Take a look at the Path class which provides some methods to deal with path strings. Think the GetFileName or the GetFileNameWithoutExtension method should do the job.
www.troschuetz.de
|
|
|
|
|
|
i have to use textbox.becouse i want transmit content of this textbox to another textbox in another form.
|
|
|
|
|
i have to use textbox.becouse i want transmit content of this textbox to another textbox in another form.
i think that i should use from html but i dont know how?
|
|
|
|
|
The TextBox control doesn't support different fonts in the same TextBox. It's all one font or nothing. You can't change the font of a selection in a TextBox. Also, a TextBox control doesn't know how anything about HTML...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
We've a component that uses "osql.exe" to run an installation script and get a bunch of datbase objects (tables, triggers, stored proc...etc) installed on SQL Server. Is there something we can use with Oracle and MySQL to perform this same task? Thanks.
Norman Fung
|
|
|
|
|
They both have their own command-line applications. MySQL's is simply mysql.exe, but I don't know what Oracle's is. I would suggest either looking it up with google or find an Oracle newsgroup.
Might I recommend a better alternative, though? Nothing gaurantees that those command shells will be resolvable (in fact, IIRC, mysql.exe is not - it's in a directory that is not in the PATH env. var.). A better way might be to use a connection to their master databases (might have different names for each major database, but for SQL Server it is called "master") and then use whatever IDbCommand implementations that are appropriate for the database you're accessing (like SqlCommand , OleDbCommand , etc.) to build database objects. This is a pretty typical solution and doesn't rely upon command shells that may or may not exist.
Another scenario is if you're building database objects on a remote machine. The local machine may not the database installed so the command shell won't be present anywhere on the local machine.
For this reason, we use the method I outlined to build and update SQL Server databases, which should work just fine with any other RDBMS.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Heath. We have our own script runner which does this, but thing is, it doesn't handle certain situations well. For instance, comment block - while we can take out the commments, it makes the scripts a hell lot harder to read and to maintain.
|
|
|
|
|
HI~
I would like to ask
How do I change the data in C++ dll by a C# program?
I have ever tried this.
I wrote a dll with VC++. There is a variable in the dll (e.g "m_string"). "m_string" is a LPCTSTR type and it's inital value set by constructor is _T("Hello World"). I also wrote a function for setting the variable. The function is declared like this:
extern "C" _declspec(dllexport) void set(LPCTSTR s)
{
m_string = s;
}
Afterward, I wrote a C# dll assembly. The C# dll import the dll written by C++. The import the dll like this:
#region DLLImports
[DllImport("Test.dll")] //test is the C++ dll filename
private static extern void Set(string s);
#endregion
Finally, I wrote a form to call the method "Set". After the method have finished executing, the value "m_string" does not change. The "m_string" is still "Hello World".
My question is, how to change a variable in dll permanently by a C# library or exe?
Thanks
|
|
|
|
|
First of all, using LPTSTR or LPCTSTR uses an ANSI or Unicode string depending on whether or not the UNICODE (or sometimes _UNICODE) symbol is defined. Unicode is only natively supported on Windows NT (4.0, 2000, XP, 2003, and all newer versions). So, you need to change your declaration like so:
[DllImport("Test.dll", CharSet=CharSet.Auto)]
private static extern void set(string s); Also notice how set uses a lower-case "s"? Your method signatures have to match (minus the "A" or "W" at the end, if you do that for different sigs for different platforms) character-for-character and case-for-case, otherwise you have to set the actual function name to P/Invoke in the DllImportAttribute 's EntryPoint field in the attributed P/Invoke method.
Finally, make sure that Test.dll is in the same directory as the executing process (not just the same as the assembly that uses it) or in another directory specified in your PATH environment variables. Native executables use this to find DLLs (and other executable files) at runtime, so the Test.dll must be resolved.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
HI~
I am sure the function work properly.
My situation is that
The dll is loaded will windows startup. The dll is used to so a string on the screen when the windows startup. The string is a variable of the dll. When the dll is loaded, a WM_PAINT message is sent and the OnPaint function is called. The OnPaint function draw the window and text on the screen. I would like to use C# program to make changes to the string so that the screen can show different string dynamically.
I use the code above and try to achieve this result. However, the variable within the extern function is changed but after the function is complete, the string on the screen still not been changed.
So, how to achieve the correct result?
Thanks~
|
|
|
|
|
Changing the variable is not enough. You have to invalidate the client area in your unmanaged DLL so that when the WM_PAINT message is called the invalidated region is redrawn. In your OnPaint handler, get the string value and draw it on the screen.
There are many ways to invalidate a region in C/C++, and since I'm guessing that you're using MFC (judging by the OnPaint event), you can use Invalidate or InvalidateRect , both inheritted from CWnd .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yes
The dll will send a message to itself every 2 or 3 second call a function. The function is written by me, which use to check whether the variable have been changed or not. If there is any variable change, the function will return true, otherwise, it will return false. If true is returned, a refresh message will be sent to the dll and force to redraw the screen. However, the screen is refreshed by the variable which shown on the screen still not changed.
I think that there may be a solution. There is a handle for the variable. First, the C# program call the extern function of the unmanaged dll and return the handle of the variable to C#. And then C# program use this handle and pass it to the extern function of the unmanaged dll as argument and call it to set the variable value. However, I do not know the unmanaged dll code well.
Can anyone tell me how to solve it?
Thanks
|
|
|
|
|
There is a solution, and that's what I've been trying to tell you. This is actually quite an easy problem and I deal with interop problems more difficult than this almost daily.
The big problem is that I'm not really understanding what you're trying to do, so let me pose what I'm hearing and tell me if I'm right:
You've defined a set function (C-style export?) in a native DLL that is resolvable and being P/Invoked by a managed assembly written in C#. The C# code calls set which changes a variable. This native function returns true or false (1 or 0, respectively). The C# code then sends WM_PAINT to the HWND that displays the string. Your handler for the WM_PAINT message draws the string value.
If I'm right and if the string value is truly being changed unmanaged process space, then the only problem could be invalidation of the client area. Depending on the WM_PAINT handler, only invalidated regions may be redrawn (this is common for most controls - only redraw what needs to be redrawn). If you don't invalidate the area of the control that displays the string, it may not get redrawn. This is why you must invalidate the region as I mentioned before.
You can try a simple test, too. After the variable is changed, minimize or otherwise hide the window (perhaps with another window). Then show it again. Is the correct string displayed now? If so, it's definitely a drawing problem and you need to invalidate the area. It could also be that, if you're using double-buffering, you're not clearing the back buffer so that even though the client area is invalidated the old back buffer is still being rendered with the old string.
All this talk about handles now is confusing me. Before you said you had a simple function declared (IIRC) like bool set(int) , correct? Now you're talking about handles (addresses).
If you need to set the address of a string, you should pin it and use something liket his:
GCHandle handle = GCHandle.Alloc("Some string or variable");
IntPtr ptr = handle.AddrOfPinnedObject();
set(ptr);
handle.Free(); If the string is to be allocated in a certain way (either using GlobalAlloc or COM's CoTaskMem object), then you can use the respective methods defined on the Marshal class to help.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Sorry
I mean there is a handle in the unmanaged dll for the variable. C# program can call a the extern function to get the handle of the variable. Then the C# program call the set (handle, new_value) to set the variable. Actually, I don't know how to implement the dll as I am familiar with it.
Can it works?
Thanks~
|
|
|
|
|
I am using HWnd handler to handle the window.
So I cannot use Invalidate or InvalidateRect function
|
|
|
|
|
Sure you can - how do you think it's done in native C/C++ applications? MFC also does it, and MFC is just wrapper classes for native Windows APIs.
P/Invoke InvalidateRect :
[DllImport("gdi32.dll")]
private static extern bool InvalidateRect(IntPtr hWnd,
ref RECT lpRect, bool bErase);
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
HI,
I want to extend Windows.Forms.DataGrid class so I can add buttons to data grid's columns.
I haven't found any good sample of this over the internet... if any body has link to a better example/sample - please forward me that URL
thanx in advance
|
|
|
|
|
You mean in the headers, or in the columns themselves? You don't need to "extend the DataGrid" to do this, though. You simply implement a DataGridColumnStyle derivative. If you look at the class documentation[^] for the DataGridColumnStyle , it even gives you a completely example that hosts a DateTimePicker control in the data columns.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
how to insert icon into text box and like yahoo messenger ?
|
|
|
|
|
TextBox doesn't support it, but a RichTextBox does...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I want to write a Windows Service application that will detect and then perform some tasks whenever a client logs on to the domain. This service will be running on a server with Active Directory. Can someone point me to the right set of .NET (C#) classes or methods that I would need to use for detecting a domain logon event?
|
|
|
|
|
The concept your describing is a Logon Script. It runs whenever a user logs on. You can write them in any script language, JScript, VBScript, .NET Script, ...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|