|
|
Will it "do" if you skip the KeyUp-event? E.g., if you put a "return" on the first line of the event, does the <del>-key work?
There's an e.Handled that might eat your key
I are troll
|
|
|
|
|
|
In what event did you put this code? Can you post your "entire" KeyUp?
Prajeesh wrote: If I get the position I can remove the character.
You can get the position of the cursor by looking at the SelectionStart property. It will hold the location of the cursor in the text, whether there's a selection or not. Removing the character right to it might 'restore' the functionality.
I suggest that you try to "fix" the code instead of looking for a workaround
I are troll
|
|
|
|
|
|
Prajeesh wrote: EditClear.ShortcutKeys = Keys.Delete;
Does the <del>-key work again if you comment out this line?
I are troll
|
|
|
|
|
|
A nice workaround
It could very well be that one of the buttons on the form has the <del> key set as a shortcut. That could eat the key, I suppose.
Happy Programming!
I are troll
|
|
|
|
|
I am comparing data fields, and setting values where differences occur like so:
foreach (DebtorDataSet.DebtorRow row in debtorDataSet.Debtor.Rows)
{
if (row.CorrespondenceSource == "D" || row.CorrespondenceSource == "J")
{
if (row.HouseName != row.CorrespondenceHouseName)
{
row.CorrespondenceHouseName = row.HouseName;
}
if (row.NoStreet != row.CorrespondenceNoStreet)
{
row.CorrespondenceNoStreet = row.NoStreet;
}
}
}
but I am getting an error due to underlying data being DBnull.
Elsewhere in my project I use a helper class for such situations:
public static object getDefaultIfDBNull(object obj, TypeCode typeCode)
{
if (obj == DBNull.Value)
{
switch (typeCode)
{
case TypeCode.Int32:
obj = 0;
break;
case TypeCode.Double:
obj = 0;
break;
case TypeCode.String:
obj = "";
break;
case TypeCode.Boolean:
obj = false;
break;
case TypeCode.DateTime:
obj = new DateTime();
break;
default:
break;
}
}
return obj;
}
but the values don't get a chance to be passed to the helper class if I try to use something like:
if (getDefaultIfDBNull(DebtorDataSet.Debtor[0].SolicitorBuilding, TypeCode.String) != getDefaultIfDBNull(row.CorrespondenceHouseName,TypeCode.String))
{
row.CorrespondenceHouseName = DebtorDataSet.Debtor[0].SolicitorBuilding.ToString();
}
How can I correctly accommodate when underlying data is DBnull, via code, please?
|
|
|
|
|
I fixed it with a syntax change so:
if (getDefaultIfDBNull(row["PostTown"], TypeCode.String) != getDefaultIfDBNull(row["CorrespondencePostTown"], TypeCode.String))
{
row.CorrespondencePostTown = row.PostTown;
}
|
|
|
|
|
[Serializable]
public class DrawableObject {}
[Serializable]
public class Layer : DrawableObject, IList<DrawableObject> {}
[Serializable]
public class Graphic : DrawableObject { }
static void Main(string[] args)
{
Type[] extraType=new Type[]{typeof(DrawableObject),typeof(Layer),typeof(Graphic)};
Layer layer = new Layer();
layer.Add(new Graphic());//add Graphic is ok.
layer.Add(new Layer()); //add Layer occur error
TextWriter textWriter = new StreamWriter("layer.xml");
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Layer), extraType);
xmlSerializer.Serialize(textWriter, layer);
}
There is a exception in Serialize().
InnerException said it cannot include Layer.
Is it possible to make this
<Layer>
<Layer>
<Layer>
<Graphic></Graphic>
</Layer>
<Graphic></Graphic>
</Layer>
<Graphic></Graphic>
</Layer>
|
|
|
|
|
It think, basically, its a case of implementing IXmlSerializable in your classes if you want to finely control how the classes are serialized to Xml. There are also a number of attributes in the System.Xml.Serialization namespace that you can adorn your classes with.
I wrote this small console application sample to demonstrate to you the IXmlSerializable route, which I think will suit you better.
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
Layer layer = new Layer();
layer.DrawableObjects.Add(new Graphic());
layer.DrawableObjects.Add(new Layer());
XmlSerializer s = new XmlSerializer(typeof(Layer));
s.Serialize(Console.Out, layer);
Console.ReadLine();
}
}
public abstract class DrawableObject : IXmlSerializable
{
#region IXmlSerializable Members
public virtual XmlSchema GetSchema()
{
throw new NotImplementedException();
}
public abstract void ReadXml(XmlReader reader);
public abstract void WriteXml(XmlWriter writer);
#endregion
}
[Serializable]
[XmlRoot("Root")]
public class Layer : DrawableObject
{
private List<Drawableobject> drawableObjects = new List<Drawableobject>();
public List<Drawableobject> DrawableObjects
{
get
{
return this.drawableObjects;
}
}
public override void WriteXml(XmlWriter writer)
{
writer.WriteStartElement("Layer");
foreach (DrawableObject obj in this.drawableObjects)
obj.WriteXml(writer);
writer.WriteEndElement();
}
public override void ReadXml(XmlReader reader)
{
throw new NotImplementedException();
}
}
[Serializable]
[XmlRoot("Graphic")]
public class Graphic : DrawableObject
{
public override void WriteXml(XmlWriter writer)
{
writer.WriteStartElement("Graphic");
writer.WriteEndElement();
}
public override void ReadXml(XmlReader reader)
{
throw new NotImplementedException();
}
}
}
|
|
|
|
|
Thanks, It is helpful
|
|
|
|
|
Hello everybody.
Let's imagine we have webbrowser control navigated to http://www.codeproject.com, so top banner image advert.gif shows ad1 picture (generated randomly).
How to save this image to the hard drive without requesting it from the server a second time?
If we try to retreive it once again, the advert.gif will show another ad picture, not the one from webbrowser control. I mean the following sample is not ok:
System.Net.WebClient wc = new System.Net.WebClient();
HtmlElementCollection imgs = this.webBrowser1.Document.GetElementsByTagName("img");
for (int i = 0; i < imgs.Count; i++)
{
wc.DownloadFile(imgs[i].GetAttribute("src"), "c:\\images" + i.ToString() + ".jpg");
}
|
|
|
|
|
Sounds like you're doing this backwards.
- Intercept the URL that the user wants to navigate to
- Download and cache all the files for that page
- Set the browser control to point to your own application's cache
- Profit!
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Thanks!
But how to extraxt already loaded image from the webbrower?
|
|
|
|
|
Unfortunately, the only way to get that is to read the browser's cache. If you're using the stock WebBrowser control in System.Windows.Forms , then you're going to have to read the Internet Explorer cache, assuming that the user has their Internet Options set to cache pages.
To read IE's cache, you're going to have to interface with the Win32 API. Specifically, read this article[^] found right here on The Code Project.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
hi all,
am developing an excel com addin using c#. In my addin, I am supposed to
generate few buttons on the excel sheet's cells and perform their respective events on clicking.
Every thing is working fine. Every button is named 'search' and is associated
with its appropriate event handler(searchButton_Click). The button and its
event handler constitute an object(of 'result' class). Now I tried to
serialize the class Result so that I can save all the currently exisitng
'Result' objects, on the active sheet, to a file such that if I save this excel sheet and re open
the sheet, I should be able to get back the controls(de serialize) of all the
buttons present on the saved sheet. How ever in the serialization step, I am
getting an exception that says:
[System.Runtime.Serialization.SerializationException] = {"Type 'System.__ComObject' in Assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable."}
Could anyone here please help me identify the exact problem here and am I
missing anything? I did mark the class 'result' as 'Serializable'. In my
'result' class I have the code to generate a button on the sheet's active
cell and that button's event handler.
The buttons am generating on the excel sheet's cells are 'MSForms.CommandButton' types.
Many thanks in advance!
|
|
|
|
|
Did ya Google it? I just did and found a crap ton of results!
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Hey, i did google but still not able to understand why am I not able to do it.
Also, I have a doubt, if am doing some thing like this(code below) in a normal project(not an excel addin),this is working fine:
emp[] e = {
new emp(1,"Mark",5000),
new emp(2,"Mich",6000),
new emp ( 3, "Amol", 4460 ),
new emp ( 4, "Anil", 9456 ),
new emp ( 5, "Srikanth", 9500 ),
};
//SERIALIZING PART
Stream s = File.Open("c:\\New Folder\\emp.txt", FileMode.Create,FileAccess.ReadWrite);
BinaryFormatter b = new BinaryFormatter();
b.Serialize(s, e);
s.Close();
//DESERIALIZING PART
s = File.Open("c:\\New Folder\\emp.txt", FileMode.Open, FileAccess.ReadWrite);
emp[] ee = (emp[])b.Deserialize(s);
foreach (emp ez in ee)
MessageBox.Show(ez.ToString());
s.Close();
But, the same is not working when am introducing this piece of code in my excel-addin project. What could be the reason for this behavour?!
Thanks.
|
|
|
|
|
Hello
I am doing C#.NET application.I want to run a background process until my application exit.How can I implement the above using thread.
|
|
|
|
|
Like this:
using System;
using System.Threading;
namespace BackgroundThread
{
class Program
{
static void Main(string[] args)
{
Thread t = new Thread(BackgroundMethod);
t.IsBackground = true;
t.Start();
Console.ReadLine();
}
private static void BackgroundMethod()
{
while (true)
{
Thread.Sleep(1000);
Console.WriteLine("Tick");
}
}
}
}
Regards,
Rob Philpott.
|
|
|
|
|
Try using BackgroundWorker component which u can find in ToolBox of Visual Studio.
Krishnraj
|
|
|
|
|
BackGroundWorkers are for forms though, maybe his program doesn't have a form.
Though, if you use a form, the BackGroundWorker is the easiest way to go.
Just remember to lock any objects while they're being worked on, but beware of dealocks (more than one thread locking the same object).
|
|
|
|
|
Dear All
I want a simple threading example in VS 2005 C#. When i run the project it should display a label with yellow background and increases it width 1px witn 1000ms interval.
I have googled it out but they are using delegates & some are using timer but i dont want to use both.
Any kind of help will be appreciated.
Thanks.
|
|
|
|