|
Hi,
Thanks for the reply, but that's not what i'm looking for. When i try and use a color containing alpha channels as any type of background color on a component, it throws an exception.
i.e.
this.BackColor = Color.FromArgb(0,this.BackColor);
This is a custom component, not one that is pre built into .net, and i know that these ones do support alpha channels, so i'm a bit confused as to how to implement it in mine.
Cheers
Cata
|
|
|
|
|
Hi!
I need help, my problem is that i need to know when the scrollbar in a RichTextBox reaches the bottom. I know that vScrollbar and hScrollbar has a value that you can set or get but how to do this in a RichTextBox?
Thanks!
Johan
|
|
|
|
|
You can either P/Invoke SendMessage and use the SBM_ messages to sent to the handle for the RTF control (see RichTextBox.Handle , inheritted from Control ), or P/Invoke the recommended scroll functions like GetScrollPos :
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.SysInt)]
private static extern int GetScrollPos(IntPtr hWnd,
[MarshalAs(UnmanagedType.SysInt)] int nBar);
private const int SB_HORZ = 0;
private const int SB_VERT = 1;
private const int SB_CTL = 2; To note, GetScrollPos is provided for backwards compatibility for older code and the Platform SDK docs recommend that you use GetScrollInfo instead, which also requires that you declare a struct for use with the P/Invoke method.
Using the method above, you can get the scroll position for the range (the page in this case) using something like this:
int pos = GetScrollPos(myRTFControl.Handle, SB_VERT); If you need to know what the range is, you can use the GetScrollRange . In this case, though, you could actually get both the position and range back at the same time if you did use GetScrollInfo . This is enough information to get you going, though.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for the answer!
I will try it!
/Johan
|
|
|
|
|
I cant get it to work...
mabye i do it wrong??
I have tryied the GetScrollPos as in the code above but i get a error when i run the program that is:
marshal return value: Invalid managed/unmanaged type combination (Int32/Uint32 must be paried with I4 or U4)
And i dont know how to work this one out...
Please help...
Thanks
Johan
|
|
|
|
|
Oops, typo! Change UnmanagedType.SysInt to UnmanagedType.U4 as the exception message suggests.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a Xml document like this and i want to show the databases of session "Development" in a datagrid. But i don't know how.
If i do it like this:
ds.ReadXml(@"c:\xmlfile.xml");
dataGrid1.DataSource = ds;
dataGrid1.DataMember = "database";
He will take the databases of both sessions, i just want the databases of the first OR the second session.
Thx in advance.
<?xml version="1.0" standalone="yes"?>
<sessions version="1.0">
<session name="Development">
<databases>
<database name="ffw100">
<physicalname>fastforward</physicalname>
<databaseorder>1</databaseorder>
</database>
</databases>
</session>
<session name="AppserverDevelopment">
<databases>
<database name="ffw100">
<physicalname>fastforward\ffw100</physicalname>
<databaseorder>1</databaseorder>
</database>
</databases>
</session>
</sessions>
|
|
|
|
|
That's not a valid format for a DataSet , so you won't be able to bind to the elements you want. DataSet s have either 2 or 3 levels. In the case of 1 level below the root (which is required by XML) a generic table name is used, IIRC, like "Table1", but you can always just use dataSet1.Tables[0] . In the case of 2 levels below the root each parent element is the table name and each child (leaf) element is a field. Each instance of the parent elements counts as a row, like so:
<DataSet>
<Table1>
<ID />
<Name />
</Table1>
<Table1>
<ID />
<Name />
</Table1>
<Table2>
<Stuff />
</Table2>
</DataSet> So this DataSet would have to two tables named "Table1" and "Table2". Table1 would have two rows and Table2 would have one. There's really not any other ways you can represent such a simple structure.
My suggestion is to extract the <databases< element(s) and put those into a separate DataSet (see the XmlDataDocument for some help with that) and bind against that.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
As Heath mentioned, your XML file is too complex for the dataset to properly parse. However, once you do have a dataset representation, binding to a specific session can be done by using a DataView of the table and setting the Row filter.
For example, I modified your source XML as follows, so that it can be parsed by the dataset.
<br />
<?xml version="1.0" standalone="yes"?><br />
<databases><br />
<br />
<!-- Development Sessions --><br />
<br />
<database><br />
<name>ffw100"</name><br />
<session>Development</session><br />
<physicalname>fastforward</physicalname><br />
<databaseorder>1</databaseorder><br />
</database><br />
<br />
<!-- AppDevelopment Sessions --><br />
<br />
<database><br />
<name>ffw100</name><br />
<session>AppDevelopment</session><br />
<physicalname>fastforward\ffw100</physicalname><br />
<databaseorder>1</databaseorder><br />
</database> <br />
</databases> <br />
Once you have the dataset, you can use a dataview to filter it before biding to the grid. The following code will bind the grid to only those databases used in the "Development" session. It will also sort by the "DatabaseOrder" node.
<br />
DataSet ds = new DataSet();<br />
ds.ReadXml(@"c:\test.xml");<br />
<br />
DataView dv = ds.Tables[0].DefaultView;<br />
dv.RowFilter = "SESSION='Development'";<br />
dv.Sort = "DATABASEORDER ASC";<br />
<br />
dataGrid1.DataSource = dv;<br />
dataGrid1.DataMember = "NAME";<br />
dataGrid1.DataBind();<br />
Hope that helps.
--Jesse
|
|
|
|
|
thx for your answer but i'm not allowed to change the Xml-file
I'm going to try now to get 1 session out the xml and save to a new file then use that to work with and when it's done bring it back to the original Xml-file.
Possible? Hope so
|
|
|
|
|
Can you Please give me an example of
client - server communication in .NET
using Remoting and configuration files.
I had problem with example given in several books.
|
|
|
|
|
There are a lot of tutorials right here on CodeProject.
Chek this section:
http://www.codeproject.com/csharp/#Remoting
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
When doing Remoting Configuration on client side
Can I have multiple entries under <client> like:
<client>
<wellknown type...>
<wellknown type...>
</client>
in the configuration file.
If yes, then how can I choose a particular entry and
get a proxy remote object.
|
|
|
|
|
If I understand your question, I think what you are trying to do is connect to one of multiple remote servers. If so...here is your solution which works for me today.
First, get rid of your client config.
Next you want to establish your channel and load your remote objects dynamically with code as well as having the ability to reset your location to go to a new server.
The reset is basically : at the time a new server is requested you close your connection and free up your channel.
Getting the channel is very generic. I use SOAP over HTTP is my connection returns the 'Version number error' and I use Binary over HTTP otherwise for speed and agility.
When the user has selected a location (in this code it is stored in a string variable named (obviously) url:
public static void reSetWebsite(NamedWebsite passedWeb)
{
currentWeb = passedWeb.Clone();
globalObjects = null;
if (channel != null)
ChannelServices.UnregisterChannel(channel);
}
public static void InitializeRemoting(bool DebugState)
{
try
{
if (DebugState == false)
{
channel = new HttpChannel(null,
new BinaryClientFormatterSinkProvider(),
new BinaryServerFormatterSinkProvider());
System.Diagnostics.Debug.WriteLine("MyApp has not been requested to run in debug mode.", "Remote Communication Manager");
}
else
{
channel = new HttpChannel(null,null,null);
runningInDebugMode = true;
System.Diagnostics.Debug.WriteLine("MYApp has been requested to run in debug mode.", "Remote Communication Manager");
}
channel.Properties["proxyName"] = null;
channel.Properties["useDefaultCredentials"] = "true";
ChannelServices.RegisterChannel(channel);
}
catch (System.Exception exc)
{
throw new System.Exception("Problem initializing the remote object channel", exc);
}
}
public static void LoadGlobalManager()
{
try
{
string location = url + "\GlobalManager.rem";
globalObjects = (IGlobalManager) Activator.GetObject(
typeof(IGlobalManager),
location);
System.Diagnostics.Debug.WriteLineIf(runningInDebugMode, "Placing remote communication library in debug mode", "Remote Communication Manager");
globalObjects.SetDebug = runningInDebugMode;
}
catch (Exception se)
{
throw new ApplicationException("Load of global objects failed", se);
}
}
_____________________________________________
Of all the senses I could possibly lose, It is the one called 'common' that gets lost the most.
|
|
|
|
|
When ever I put a node into the treeview I get
horizontal scrollbar immediately.
Ho do I avoid It?
How can I customize the TreeView Scroll Bar like backcolor etc.
|
|
|
|
|
When doing Remoting Configuration on client side
Can I have multiple entries under <client> like:
<client>
<wellknown type...>
<wellknown type...>
</client>
If yes, then how can I choose a particular entry and
get a proxy remote object.
|
|
|
|
|
If you configure .NET remoting by calling RemotingConfiguration.Configure , passing the path to the file that contains this (often the application's .config file), then you can either use the new operator (just like you use to instantiate any other class) or Activator.CreateInstance . Since each client instance of the <wellknown> element includes a type, when the the CLR create a new instance of the class the remoting infrastructure creates a new proxy for your type.
So, if you had something like this:
<client>
<wellknown type="Class1, MyAsm" url="tcp://localhost:8000/Class1.rem" />
<wellknown type="Class2, MyAsm" url="tcp://localhost:8000/Class2.rem" />
</client> Then a simple call to new Class1() would create the first well-known object.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a main application that is referenced by a plugin. I would like the plugin assembly to be copied into the main application folder. Currently I have to do it manually because VS.net will not allow me to add a circular dependency.
Any solutions?
|
|
|
|
|
The solution is a simple logical solution: a plugin should typically not have a dependency on the application that hosts it, but perhaps a shared assembly that the application uses. Having the plugin depend on the application itself makes your design very inflexible.
Worse yet, never have a dependency on your plugin. The whole idea of plugins is that they can be added or removed from your application (either before executing it or while executing it) without the application knowing about it. This is where polymorphism comes into play. You either use interfaces or abstract classes declared in a shared assembly that plugins reference. They extend the abstract class and/or implement the required interfaces. Your application communicates with the plugins through these classes or interfaces without knowledge of the actual implementation. This is the entire fundation of COM, .NET (a progression of COM, but not a replacement), web services, and many other technologies. All communication is done through a common interface (also called a "contract") so that the implementation is hidden. That's a true plugin.
These plugins could be loaded from the .config file (common in .NET applications), some other file or the registry (which COM uses, but is not recommended for .NET code for deployment reasons), or even enumerated in a directory and loaded.
There are many articles here on CodeProject that discuss various implementations of plug-in system. Just try a search for "plug-ins" or something similar.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I understand all of that. It's just the way I worded it.
My solution: create an xml files that holds the plugins currently in use. For plugin paths just use the existing file structure without copying the files to the local directory.
I admit I should not have been working for the 18 hour that day.
|
|
|
|
|
Why not have the plugin simply implement a delegate/event? The main application would add a handler for that event. Each time the event is caught, the main app could make a call into the plugin. Hence the plugin would initiate a call from the main app.
|
|
|
|
|
Hi guys & experts,
wanna ask u some questions...
I've managed to create a windows media player custom control, which inherits from HtmlControl, but having problem in setting the URL attribute. Here's the code:
<br />
using System;<br />
using System.Web;<br />
using System.Web.UI;<br />
using System.Collections;<br />
using System.Collections.Specialized;<br />
using System.Reflection;<br />
using Microsoft.MediaPlayer;<br />
using System.Web.UI.HtmlControls;<br />
using System.Web.UI.WebControls;<br />
<br />
<br />
namespace LogPlayer1<br />
{<br />
public class MediaPlayer : HtmlControl <br />
{<br />
<br />
<br />
public MediaPlayer()<br />
{<br />
<br />
Url = WebForm1.passedURL;<br />
<br />
<br />
}<br />
public string Url <br />
{ <br />
get { return (string) ViewState["Url"]; } <br />
set { ViewState["Url"] = value; } <br />
} <br />
protected override void Render(HtmlTextWriter writer) <br />
{ <br />
writer.WriteBeginTag("OBJECT");<br />
writer.WriteAttribute("style", "Z-INDEX: 101; LEFT: 152px; WIDTH: 464px; POSITION: absolute; TOP: 160px; HEIGHT: 397px"); <br />
writer.WriteAttribute("classid", "clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6");<br />
<br />
writer.WriteBeginTag("param");<br />
writer.WriteAttribute("name", "URL"); <br />
writer.WriteAttribute("value", Url); <br />
writer.WriteEndTag("param"); <br />
<br />
writer.WriteEndTag("object"); <br />
<br />
}<br />
<br />
}<br />
}<br />
<br />
<br />
This code basically writes the the windows media player to the ASPX file. but somehow I can't set the URL. The WebForm1.passedURL is a variable containing the url of the file. I've done some tests, and proven that the passedURL value is passed to the MediaPlayer class, but somehow cannot be set as the URL of the windows media player object. Or maybe the player won't play it for some reason. Could any of u give any solutions to this?
thanks in advance guyz
|
|
|
|
|
NEVER have a class request information from its parent in this way! This is WAY to tightly coupled. In your page, you simply set this control's Url property to whatever you want, just like you wouls set the <asp:HyperLink> 's NavigateUrl property, for instance, or many other contro's Text properties, etc. Why else would you declare it as a property? Your class is request accessing from a particular instance, which is completely the wrong way of doing it. Callers of your class set properties. In this case, that may be either the .aspx or .ascx file that contains the element for your control or your code-behind file.
Also, there are a couple of different param names that Windows Media Player uses depending on which version you're embedding. You should look at the Windows Media SDK on MSDN[^] and/or check out other examples online to use the right property with the right CLSID (class ID, a GUID).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
sorry... don't really understand your language... could u explain more?
thanks
|
|
|
|
|
You don't understand simple object-oriented development? Think, for example, of Console.WriteLine . Does it ask you what to print, or do you tell it? The latter of course.
Your WMP control should have the Url property set by the container control (like the Page or other container), just like they set the Text property of a Label or the NavigateUrl or a HyperLink control either in the HTML declaration of your control, or programmatically. NEVER request a property from a page like that, which wouldn't work properly anyway without a reference to the page itself (and a cast in order to get a field defined in your class, not the Page or other container control's class).
It's a simple difference between callers and callees. Just look at all the other server controls declared in your page. Are they asking your page for data, or does your page provide the data to them. Again, the latter case is true. Your control should act no differently, such that in your .aspx you might find:
<uc1:wmp id="wmp1" runat="server" url="/path/to/file.wmv" /> ASP.NET uses the url proeprty to set your Url property in your class, and when the Render method is called by ASP.NET your code will get the value of that property. At no point does this code request a variable from some page.
Microsoft MVP, Visual C#
My Articles
|
|
|
|