|
You might want to take a look at the System.Text.Encoding class, which can encode and decode strings and byte[] arrays to/from different encodings (even particular code pages, which don't apply to Unicode). Make sure you also set the HttpWebRequest.ContentEncoding to the proper type, or for multipart-MIME the particular Content-Type (and charset) for a MIME part. In either case, the Encoding class will help.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
What is the way to create fast links from highlighted words in a richTextBox to certain parts in text of this or other's richTextBoxes?
I want to have an available description of some highlighted items in richTextBoxes when the user clicks on them.
|
|
|
|
|
There's a LinkClicked event available which you'll have to handle.
By default, standard links (beginning with http:// or ftp:// and a few others) are displayed as links and fire the event when clicked.
If you want other parts (esp. not starting with <protocol>://) then you'll have to use interop to set the correct character attribute (CFE_LINK) to the text range you want to act as a link.
You might use this article on MSDN as a basis for extending your RichTextBox to add support for something like SetSelectionLink() .
Regards,
mav
|
|
|
|
|
....................................<br />
richTextBox1.LinkClicked += new LinkClickedEventHandler(Link_Clicked);<br />
................................................<br />
protected void Link_Clicked(object sender, LinkClickedEventArgs e)<br />
{<br />
.................................................<br />
}
Could someone tells me how: when click on an item in the richTexBox1 to display a specific area of the richTextBox1 ?
Thank you mav.northwind for your response.
Could I have a more specific answer?
|
|
|
|
|
Use Select() to set the Cursor to the location you want to display and then call ScrollToCaret().
mav
|
|
|
|
|
I could use another richTextBox2 which supposed to be a large text since it contains all the text and should be invisible all the time and the only I see will be the richTextBox1.
Also to put a Keyword at the start point of the certain text area in the richTextBox2 and another at the end point of that area. Then:
int start = richTextBox2.Text.IndexOf(myStartKey) ;<br />
int end = richTextBox2.Text.IndexOf(myEndKey) ;<br />
richTextBox2.SelectionStart = start ;<br />
richTextBox2.SelectionLength = end-start+1 ;<br />
richTextBox1.Text = richTextBox1.SelectedText ;
But if I do not use www or ftp could I have an example of what I can use to make items have an appearance and behavior like them ?
|
|
|
|
|
Please stop shouting.
As I stated before, to make part of your RichText to have link appearance and behaviour (blue foreground, underlined, fire LinkClicked event), this part of text has to have the right flags set (CFE_LINK) in the underlying RichEdit control.
These flags (and several others) cannot be set from .NET alone, that's why I've added a section to the MSDN article on how to make only part of your text Bold (or italic or Size 12 or a link) without affecting other properties.
Please read the article, it's all explained there.
The only thing you have to do basically is to duplicate the SetSelectionBold() function from RichTextBoxEx , for example, and change CFE_BOLD to CFE_LINK .
Then add your keyword to the RichTextBoxEx, select it and call your newly defined SetSelectionLink() function.
Voila - only the selection is underlined and will fire LinkClicked without http:// or ftp://.
mav
|
|
|
|
|
|
I'm trying to automate the kickoff of my company's test automation suite. To do this, I've written a Windows service (using C#/.NET) that checks for the presence of a signal file and then kicks off our test automation (using Process.Start()). The problem is that the test automation starts invisibly - the process is there, but no GUI, and since this is GUI testing, we need the GUI to be visible. This seems like a pretty straightforward job - start a GUI app in a visible and interactive state using a service - but I can't figure it out so far. Any suggestions are greatly appreciated.
Thanks.
|
|
|
|
|
If you look at the service in the control panel you should find and option that allows the service to interact with the desktop.
It should be under the logon tab.
This might be what you need.
Chris
|
|
|
|
|
An alternative to what Chris said is to run the service as a particular user with local login rights and an associated desktop session (if they don't, a new should be initialized when the service logs in as that user), like your user account. In this case, however, the service will only run in the specified user's desktop session (which could be in the background of another current desktop session for an interactive user).
In most cases, what Chris said is best but I just wanted to present this alternative.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks very much to both you and Chris. Chris' solution would work except that I need to have the service access a network share folder. The Local System account can't access the network resource. I tried using my own account to run the service, but my service started the test application in the background - I could see the process, but no desktop interaction. What you say makes it sound like the test application should be interacting with my desktop session, since the service is running under my account and I'm currently logged in. Can you think of any reason why it isn't?
|
|
|
|
|
You could use impersonation. See the documentation for the WindowsIdentity.Impersonate method in the .NET Framework SDK for an example.
This won't prompt for credentials, however. That's your code's job but simply requires a dialog with a couple TextBox es and Button s (or however you want it to look).
Another option - though a hack - is to set the password for the local SYSTEM account on both machines to the same password. This has worked for several other people in workgroup setups before.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi there,
i would like to receive information about a cd/dvd in my cd-rom drive. i already use the freedb and volumeinfo article's code to receive the audio track names and other details (thx a lot for the code!).
what i need is the following:
- i want to get the disk size in bytes. this works with a system.management.managementobject, but _not_ for audio cd's, it returns 0 (it works for mixed cd's and dvd's e.g.).
- what i need even more is the date when the cd/dvd was pressed/burned. this must work somehow! nero shows it! also windows shows a date for each track...
could anyone help me with that please?
greetings, have a nice week,
civc
|
|
|
|
|
|
You have to be alot more specific about what your asking and what your doing. Instance of what?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
please correct me if anything i state is incorrect about ref in C#. i'm trying to make sure i understand these 100%.
- using a ref parameter in C# for VALUE types (eg ref Int32 i) is basically the same thing as using "int* pInt" in C++.
- for reference types, C# defaults to passing references, so any function in C# (Without ref or out keyword) when passing references is basically also "classType* pObj" in C++.
- when using the REF keyword with a REFERENCE type in C#, this is essentially the same as pointers to pointers in C++. that is, in C# a function "void func (ref ClassType p)" would be written equivalently in C++ as "void func (ClassType** p), and when p is used in the C# function, such as p.memberFunction(), the equivalent in the C++ function would be (*p)->memberFunction(). in other words, in C# the levels of dereferencing are hidden from the programmer, wheras in C++ you must dereference the proper levels yourself.
is my understanding of how C# implements references correct? thanks.
|
|
|
|
|
Yes, but with one other thing. If you reassign a parameter reference without ref or out , the variable that was passed to the method will not reference the new object.
With this comes something very important, one of the few things that can truly crash the CLR. If you are P/Invoking a function that takes an LPTSTR or something as an [out] variable, do not use out or ref in your managed declaration (unless the function parameter type is LPTSTR* ). To make sure the marshaler knows to reassign the parameter, use the OutAttribute instead.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
you mean like so:
void function (MyClass myObj)
{
myobj = new MyClass();
}
so in this case, it appears that after the function call the reference to the new MyClass obj is lost and is just garbage collected, and the ref passed in would remain referring to whatever it was before the function call. right?
|
|
|
|
|
Yes, that is correct. Consider the following example:
using System;
class Test
{
static void Main()
{
Exception e = new Exception("From Main()");
Console.WriteLine(e.Message);
A(e);
Console.WriteLine(e.Message);
B(ref e);
Console.WriteLine(e.Message);
}
static void A(Exception e)
{
e = new Exception("From A()");
}
static void B(ref Exception e)
{
e = new Exception("From B()");
}
} The output would be:
From Main()
From Main()
From B() Exception was just the first object that came to mind, but any reference type - and in this case, value types - would do.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
This is a side question, but so similar I didn't want to start a whole new thread for it. I have a Managed DLL that takes a int* but I can't seem to pass anything that works (ref, out) it's a Managed DLL so I'm not using Pinvoke, but I am wondering if there is a way to do this without using unsafe code or changing the Managed DLL code (Although that probably what I'll have to do).
Thanks!!
|
|
|
|
|
An int* in unmanaged code (even though your targeting the CLR with your C++ compiler) is still a pointer to a native int, not a managed int. Try using System::Int32* . If that doesn't work, I recommend you ask in the Managed C++ forum. I've used MC++ in the past but not a whole lot. Sorry.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm developing add-in for VS and am having extreme trouble with getting ConnectionString from node in Server Explorer. I've done most of the job getting one of the node as UIHierarchyItem but I can't cast either it or it's .Object to IDispDataVwDataConn which is type when I select node and then look into property window (I found that interface in VS7DataProject)...
Maybe the problem is that the object I am casting is a COM object, the object I am casting to is a .Net wrapper - they are not really the same thing, though I was hoping all the gory details would have been taken care off for me (interop being so seemless). If anyone has a suggestion as to how to get said COM object to cast to the .Net interop type or some other way of accessing the COM object's properties directly...then that would possibly solve the whole problem....
Tnx in advance to anyone who tries to help...
|
|
|
|
|
The IDispDataVwDataConn interface must be declared in your managed code (resumably C# since you're in this forum) with the ComImportAttribute (so that the CLR QI's for the interface instead of doing a type cast), the correct GuidAttribute (with the right IID), and the InterfaceTypeAttribute with the correct value that dictates from which interface(s) the interface in question derives. The methods must also be in the correct order (when derived from IUnknown or a dual interface) and have the correct DispIdAttribute values (when derived from IDispatch or a dual interface).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
First of all tnx...
Second - am still at newbee level I guess as I can't get this thing working... So if you can I would be grateful if you could provide more pointers or answers to my questions. I included code I tried to made.
Question:
---------
Is IDispDataVwDataConn really the one needed to be set with all those attributes and defined in mine project? As it is already defined in VS7DataProject and it's managed code.
UIHierarchyItem.Object is COM object...
Code:
-----
<br />
public class TempClass<br />
{ <br />
EnvDTE containerApplication; <br />
ComboBox cmbConnection; <br />
<br />
void LetsPresumeThisFunctionGetsCalledWhenItsNeeded()<br />
{<br />
EnvDTE.Window win = containerApplication.Windows.Item(Constants.vsWindowKindServerExplorer);<br />
UIHierarchyItem uih = ((UIHierarchy)win.Object).GetItem("Data Connections");<br />
<br />
if (uih.Collection.Count > 0)<br />
{<br />
cmbConnections.Enabled = true;<br />
<br />
foreach(UIHierarchyItem item in uih.UIHierarchyItems)<br />
{<br />
} <br />
} <br />
} <br />
}<br />
tnx again mate...
|
|
|
|