|
Dunno what I was thinking about yesterday since it was pretty obvious.
private void onLoad(object sender, System.EventArgs e)
{
richTextBox1.Text = "Hello World\n";
richTextBox1.AppendText("This is the string I search for\n");
richTextBox1.AppendText("Another Hello World Again\n");
}
private void button1_Click(object sender, System.EventArgs e)
{
int loc = richTextBox1.Find("string");
int linePos= richTextBox1.GetLineFromCharIndex(loc);
int lineLen = richTextBox1.Lines[linePos].Length;
int lineStart = richTextBox1.Lines[linePos].IndexOf("string");
richTextBox1.Select(lineStart,lineLen);
richTextBox1.SelectionColor = Color.Blue;
richTextBox1.SelectedText = richTextBox1.Lines[linePos];
richTextBox1.AppendText("strPos: " + loc + ", Len: " + lineLen + ", linestart: " + lineStart);
}
|
|
|
|
|
I want to access a class (TestClass) that is in a given assembly(Test.dll) on my machine.
I use activator :
ObjectHandle objH=null;
objH=Activator.CreateInstanceFrom(@"\\Daniel\SharedDocs\Test.dll","TestClass");
TestClass tc=(TestClass)objH.Unwrap();
MessageBox.Show(tc.GetCompName());
But I get this error : "Required permissions cannot be acquired."
What should I do?
Thanks,
Daniel.
|
|
|
|
|
You should not load the DLL from a network path... instead use a local copy. Or change the default security settings in "Control Panel".
|
|
|
|
|
The exception type is : System.Security.Policy.PolicyException
I think it has somthing to do with SecurityPermission and ReflectionPermission...
|
|
|
|
|
Daniel Zaharia wrote:
The exception type is : System.Security.Policy.PolicyException
I think it has somthing to do with SecurityPermission and ReflectionPermission...
No, it has something to do with the Policy!!!
So either change your policy to allow executiong ffrom network shares or change the way you load your assembly!
|
|
|
|
|
You need to add a code group with a URL or Site membership condition with the necessary privileges (or simply FullTrust permissions) for the directory (or any parent directory) to allow execution from that directory.
For example, using a URL membership condition, use file://MYSERVER/SHARE/* or something like that. Be sure to add the asterisk at the end as a wildcard unless you only want to apply the policy to only one assembly (which, of course, you should include the assembly name).
You should read Understanding .NET Code Access Security[^] here on CodeProject for more information. It's a good read and a comprehensive resource of what you can find scattered throughout the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
I get the same error even if i try to load the assembly from the same directory with the executing assembly.
objH=Activator.CreateInstanceFrom("Test.dll","TestClass");
|
|
|
|
|
Can some1 pls tell me what's wrong with my coding? thank u.
<%@ Page Language="C#" Debug="True" %>
int AddUser(string fname, string sname, string username, string password)
{
string connectionString = "server=\'\'; user id=\'\'; password=\'\'; databas" +
"e=\'\'";
System.Data.IDbConnection dbConnection = new System.Data.SqlClient.SqlConnection(connectionString);
string queryString = "INSERT INTO [Members] ([fname], [sname], [username], [password]) VALUES (@fname, " +
"@sname, @username, @password)";
System.Data.IDbCommand dbCommand = new System.Data.SqlClient.SqlCommand();
dbCommand.CommandText = queryString;
dbCommand.Connection = dbConnection;
System.Data.IDataParameter dbParam_fname = new System.Data.SqlClient.SqlParameter();
dbParam_fname.ParameterName = "@fname";
dbParam_fname.Value = fname;
dbParam_fname.DbType = System.Data.DbType.String;
dbCommand.Parameters.Add(dbParam_fname);
System.Data.IDataParameter dbParam_sname = new System.Data.SqlClient.SqlParameter();
dbParam_sname.ParameterName = "@sname";
dbParam_sname.Value = sname;
dbParam_sname.DbType = System.Data.DbType.String;
dbCommand.Parameters.Add(dbParam_sname);
System.Data.IDataParameter dbParam_username = new System.Data.SqlClient.SqlParameter();
dbParam_username.ParameterName = "@username";
dbParam_username.Value = username;
dbParam_username.DbType = System.Data.DbType.String;
dbCommand.Parameters.Add(dbParam_username);
System.Data.IDataParameter dbParam_password = new System.Data.SqlClient.SqlParameter();
dbParam_password.ParameterName = "@password";
dbParam_password.Value = password;
dbParam_password.DbType = System.Data.DbType.String;
dbCommand.Parameters.Add(dbParam_password);
int rowsAffected = 0;
dbConnection.Open();
try {
rowsAffected = dbCommand.ExecuteNonQuery();
}
finally {
dbConnection.Close();
}
return rowsAffected;
}
void Button1_Click(object sender, EventArgs e)
{
if AddUser(txtUserName.Text, txtUserPassword.Text) > 0
Message.Text = "Success";
else
Message.Text = "Failure";
}
<asp:label id="Label1" runat="server">User Name
<asp:textbox id="txtUserName" runat="server">
<asp:label id="Label2" runat="server">Password
<asp:textbox id="txtUserPassword" runat="server" textmode="Password">
<asp:label id="Message" runat="server">
<asp:button id="Button1" onclick="Button1_Click" runat="server" text="Register">
|
|
|
|
|
You could try the ASP.NET forum[^]
Also, I don't think people are going to go through all that code looking for your error without an idea of what they are looking for. What error message do you get? What exacly goes wrong?
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
Hi ,
I want to add a style to the particular row's text in datagrid....as my datagrid is directly take the data from store procedure....
datagrid2.datasource=ds;
datagrid2.databind();
i want to add the style like whenever my mouse is over on that text i want to change the cursor as a hand.
In the css file i created a style for the hand named "hand" ....that's the same i m using in the following code....
datagrid2.Items[i].Cells[1].Style.Add("onmouseover","hand");
plz help me....
Thanks..
|
|
|
|
|
This question really belongs in the ASP.NET forum. It has nothing to do with the C# language itself, even though it's written in C#.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I use PowerPoint 2003 to record the following macro:
<br />
Sub Macro1()<br />
<br />
Presentations.Add WithWindow:=msoTrue<br />
ActiveWindow.View.GotoSlide Index:=ActivePresentation.Slides.Add(Index:=1, Layout:=ppLayoutText).SlideIndex<br />
ActiveWindow.Selection.SlideRange.Shapes.AddPicture(FileName:="C:\SAVE\1_files\PSPage1.bmp", LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=9, Top:=22, Width:=702, Height:=496).Select<br />
ActiveWindow.View.Paste<br />
With ActiveWindow.Selection.ShapeRange<br />
.IncrementLeft 165.88<br />
.IncrementTop 79.88<br />
End With<br />
End Sub<br />
Now I want to implement it in my C# project,
<br />
ppApp = new PowerPoint.Application();<br />
objPres = ppApp.Presentations.Add(MsoTriState.msoTrue);<br />
objSlide = objPres.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutText);<br />
objShape = objSlide.Shapes.AddPicture:="C:\\SAVE\\1_files\\PSPage1.bmp",MsoTriState.msoFalse,MsoTriState.msoTrue,9,22,702,496);<br />
I can add a slide and insert the Picture,
but I don't know how to do
ActiveWindow.View.Paste
to paste the object I write into clipboard,
Can anyone tell me how to do this in C#...??
Thanks a lot !!
|
|
|
|
|
Anything you can do in VB6 (and older) you can do in a managed languages that supports COM interoperability (just about all of them, including C# and VB.NET). It's all based on OLE/COM automation described in a typelib that you can create an interop assembly from. This interop assembly is also known as a Runtime Callable Wrapper (RCW), which marshals calls from managed to unmanaged.
Unfortunately, though, it's not always as clear what to do as it is with VB (pre-.NET) because not all the type information is reserved. Properties and parameters start being the most basic class: object .
The primary interop assemblies (PIA - typically assemblies created by the developers of the corresponding typelib, and registered in a way that when you reference that typelib the PIA is used automatically instead of a new one being generated) for Office 2003 declare a DocumentWindow.View property, of type View . View.Paste is defined, so you would use:
ppApp.ActiveWindow.View.Paste();
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi there,
It's fairly easy to create a System.Drawing.Color with any RGB value one wishes. It's also easy to get this color HSB values by using System.Drawing.Color.GetBrightness , System.Drawing.Color.GetHue and System.Drawing.Color.GetSaturation member methods.
But can anyone help me create a color from Hue, Saturation and Brightness (HSB) values?
|
|
|
|
|
|
|
Hi ,
I want to add a style to the paricular row's text in datagrid....as my datagrid is directly take the data from store procedure....
datagrid2.datasource=ds;
datagrid2.databind();
i want to add the style like whenever my mouse is over on that text i want to change the cursor as a hand.
In the css file i created a style for the hand named "hand" ....that's the same i m using in the following code....
datagrid2.Items[i].Cells[1].Style.Add("onmouseover","hand");
plz help me....
Thanks..
|
|
|
|
|
Hi,
This box is not enough if I will discuss to you all about datagrid. I suggest you visit the following site and you will find all the solutions and code that you want.
http://aspnet.4guysfromrolla.com/articles/042402-1.aspx
http://wwww.datagridgirl.com
Q1. datagrid2.Items[i].Cells[1].Style.Add("onmouseover","hand");
A1. Try to go to this page "MOUSEOVER coloring and CLick Datagrid"
http://aspalliance.com/articleViewer.aspx?aId=30&pId=1
I hope this will help you.
Good Luck
/Dabuskol
|
|
|
|
|
how do i move AxPdfLib.AxPdf on the form ?
it dosent know mousehandlers.
|
|
|
|
|
As I mentioned with one of your earlier questions, an ActiveX control contains it's own message queue and .NET has no control over that. If there are events exposed on the ActiveX control, those should be declared by the RCW (Runtime Callable Wrapper) and you can use those. If it doesn't have them, there's really nothing you can do. This is not a .NET Control, merely an ActiveX control hosted within a .NET Control that does little more than marshal calls from managed to unmanaged code.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks
please help more.how can i access to RCW .and please a tell me address of related sample .
|
|
|
|
|
The very use of the Acrobat control means that you are already using the RCW. What I was saying was that the ActiveX control has to expose some interfaces that let you handle notification messages. The AxHost control merely hosts the ActiveX control. Messages passed through the message pump are not handled by the window procedure (WndProc ) for the control in the same manner that other controls' messages are handled.
For instance, if you host the WebBrowser control you can modify the AxHost -derived slightly and pass a number of interfaces to the WebBrowser control. I haven't ever needed to try this with the Acrobat ActiveX control (it would be different interfaces, if any) so I don't know if it support this. I do know that it does support ActiveX Containers, but that is beyond the scope of a simple message board.
I recommend you go to Adobe's web site[^] and look for developer information, or search the 'net with google or something. For more information on ActiveX containers, see the MSDN Library Online[^]. It's not a simple solution.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
how i serialize userControl BackGroundimage?
i wanted import windows media but i cant rigthclick and doubleclick it.
i want doubleclick in AxmediaPlayer and then open another form that select opened file.
thus i create a usercontrol and hide Axmediaplayer and then size of usercontrol put in size of windows media and show AxmediaPLayer.
now i want serialize and deserializ AxmediaPlayer but I dont Know
what i do?
thanks
|
|
|
|
|
I just answered your question before: you don't need to serialize the media player control at all. You're not sending it across context boundaries (separate AppDomains, separate processes, separate machines, etc.), so there's no reason to serialize it in order to marshal it. Either re-parent the control or use the existing methods from the PlayerApplication class I mentioned before.
You won't be able to recieve single- and double-click events from the AxMediaPlayer control as you would with other Windows Forms control because the AxMediaPlayer control is an ActiveX control with it's own thread queue (message dispatch). If the control exposes appropriate events, you can handle those, but the Click and DoubleClick events you find on other controls will not work.
See my previous post for details about re-parenting the control or using the supplied methods exposed by its typelib that you use to create an interop assembly, which I also gave you instructions on. If you don't understand them, continue the thread - don't start a new one.
Microsoft MVP, Visual C#
My Articles
|
|
|
|