|
Thanks, Nick! That makes perfect sense.
Your first example is exactly what I was trying to do.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Sometimes you can override the base classes properties, other times it is necessary to replace them using the new keyword.
In the case of Size , Control uses another readonly property DefaultSize alongside to set the initial size so that needs to be dealt with too. I've never needed to change the Location property inside the control itself as it is normally accessed by the control's host for layout within it's client area - I can't think of a reason to need to replace the default behaviour of this property.
Here's an example using new , override and an additional property
public class MyControl : Control
{
public event EventHandler IDChanged;
private static readonly Size MyDefaultSize = new Size(150, 50);
public const int MaxID = int.MaxValue;
public const int MinID = 0;
private int id;
public new Size Size
{
get { return base.Size; }
set { base.Size = value; }
}
protected override Size DefaultSize
{
get { return MyDefaultSize; }
}
public int ID
{
get { return id; }
set
{
if (value < MinID || value > MaxID)
throw new ArgumentOutOfRangeException(
"ID",
string.Format(
"ID must be between {0} and {1}",
MinID, MaxID));
if (id != value)
{
id = value;
OnIDChanged(EventArgs.Empty);
}
}
}
protected virtual void OnIDChanged(EventArgs e)
{
EventHandler eh = IDChanged;
if (eh != null)
eh(this, e);
}
}
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Thanks for the excellent example, Dave.
I was thinking, for some odd reason, that I needed to handle location and setting myself in the constructor, rather than relying on the base class to do it for me.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
i have to check if my string span to more than one lines than append space at start of each line..hw can this be done?
Regards
Ali
|
|
|
|
|
It would be great if you give some example so that I can give you proper solution.
Thanks !
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
dr[i - 1] = " " + fieldValues[i].ToString();
this is my code...it only appends space at first line of string but if string spans multiple lines hw to append space at start of each line.
|
|
|
|
|
You have to split the original string at new lines, add the space and then Join them together again. This is an example:
string original = ...;
string spaced = String.Join( "\n", original.Split( '\n' ).Select( s => " " + s ).ToArray() );
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
dr[i - 1] = " " + fieldValues[i].Replace("\n","\n ");
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
I got the help from MSDN that ViewPort3D could solve it
But I don't know how to code it
not in a WPF Project
I want to Display it in a WindowsFormsApplication Project
(in the Form1)
If display a 2DWPF I knew that DraingVisual could deal it in WFA
but How to display a 3D(WPF)?
thanks to all assistants!
This is my first question here,
and I am a new learner
Please excuse me for any faults.
|
|
|
|
|
Message Closed
modified 23-Nov-14 7:14am.
|
|
|
|
|
Thank you verry much,
and especially thanks for your introduction of the "online MSDN"
I solved it!
|
|
|
|
|
Hey,
I have a nullable 2d Double array which I want to convert to a non nullable 2d Double array. Is there any sane way of doing this?
Cheers!
Jeroen De Dauw
---
Forums ; Blog ; Wiki
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|
|
By nullable 2d array, I presume you mean an array containing double?s.
So you want to convert double?[] to double[]... What happens if there is a null in there then?
Regards,
Rob Philpott.
|
|
|
|
|
At the point where I want to convert from nullable to non nullable, there are no null values.
I indeed mean Double?[,];
Jeroen De Dauw
---
Forums ; Blog ; Wiki
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|
|
var nullableDoubles = new double?[2][];
nullableDoubles[1] = new double?[]{null, 1.1, null, 1.2};
double[][] nonNullableDoubles = nullableDoubles.Select(doubleArray=>{
if(doubleArray==null)
return null;
else
return doubleArray.Where(doubleValue => doubleValue.HasValue).Cast<double>().ToArray();}).ToArray();
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Hey,
Since I'm getting an error saying that 'double?[*,*]' does not contain a definition for 'select', I'm assuming I need to import some namespace. Which one?
Cheers!
Jeroen De Dauw
---
Forums ; Blog ; Wiki
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|
|
System.Linq
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
I'm trying to draw a PNG (with transparency) onto the screen above everything else but finding it difficult as I can only draw on forms and they are limited to a single transparent color... is there any way to draw directly on the screen's device above everything else or to make the window use a mask or something?
|
|
|
|
|
|
Hi I'm trying to program a wrapper class in C# for an unmanaged C DLL. The DLL contains a function that allows you to register a callback function so i call the register callback function and pass in my callback function, now when i call a function that uses that callback in the DLL, the function only calls it once and then my program just crashes it comes back with "ConsoleApplication1.exe has encountered a problem and needs to close. We are sorry for the inconvenience" message, the callback function only gets called once, this shouldn't happen, could this be because the garbage collector is disposing my callback function object or something ? how do i solve this problem?
Thanks.
|
|
|
|
|
We need to see the relavent code (particularly the API function C declaration, your C# implementation of it and your delegate declaration) to figure out what's going on
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
ok.
[DllImport("ProSdk.dll", EntryPoint = "RegisterStreamDirectReadCallback", CharSet = CharSet.Unicode)]
private static extern int _RegisterStreamDirectReadCallback(stream_direct_read_callback streamReadCallback, IntPtr context);
...
public delegate void stream_direct_read_callback(int channelNum, Byte[] dataBuf, UInt32 length, int frameType, IntPtr context);
...
public void stream_read_callback(int channelNum, Byte[] dataBuf, UInt32 length, int frameType, IntPtr context)
{
System.Console.WriteLine(channelNum+" channel callback func called");
}
...
stream_direct_read_callback str = new stream_direct_read_callback(stream_read_callback);
_RegisterStreamReadCallback(str, IntPtr.Zero);
is that enough information, i can give you a link to the api documentation for the dll if you want?
|
|
|
|
|
I would guess your definition of the delegate does not match what the unmanaged function expects (number of parameters, return value, calling convention), so stack gets corrupted when your callback function is called.
Unmanaged signature:
typedef int (*STREAM_DIRECT_READ_CALLBACK)(ULONG channelNumber,void
*DataBuf,DWORD Length,int FrameType,void *context);
Your code:
public delegate void stream_direct_read_callback(int channelNum, Byte[] dataBuf, UInt32 length, int frameType, IntPtr context);
You used byte[] where the unmanaged code used void*. AFAIK the marshaller will automatically convert byte[] to void*, but NOT in the other direction as needed for callbacks. Moreover, the callback seems to be using the default calling convention (C-decl), not __stdcall as the .NET marshaller expects normally.
I would try changing the delegate signature to:
using System.Runtime.InteropServices;
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int stream_direct_read_callback(int channelNum, IntPtr dataBuf, UInt32 length, int frameType, IntPtr context);
|
|
|
|
|
thanks that worked. So the C DLL was using the C-decl calling convention then ? because i thought it was using stdcall calling convetion. So that code you put above the delegate [UnmanagedFunctionPointer(CallingConvention.Cdecl)] converts it from stdcall to C-decl then?
|
|
|
|
|
I have searched the Internet and found sites that say this is possible, and others that say it is not possible. I am wondering if anyone has done it, or know a specific reason why it is not possible. This is a UI widget that we wish to make available to customers that are using an ActiveX container on Windows CE 4.2. They do not have the .Net Compact Frmaework install, but I am confident we can resolve that issue. I do not want to spend time on this if in the end it is not possible to host a .Net UI Widget within an ActiveX wrapper on Windows CE. I have read that the hosting API does not exist on CE and therefore this will not work. I am unclear what the Hosting API is, and why this means that I cannot have a COM callable wrapper for my .Net component on CE.
Tanks for your support
Pat O
<a href="http://currentchaos.blogspot.com/">Blog</a>
_ _ _
|
|
|
|