|
Straight from MSDN
Remarks
You must keep the stream open for the lifetime of the Bitmap object.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDrawingBitmapClassctorTopic6.asp
This happens sometimes when the OnPaint tries to access the BitMap and
gets a null.
Live Life King Size
Alomgir Miah
|
|
|
|
|
So it is...
But, like I said, never had a problem with it.
I fail to see why any Bitmap object (properly defined) would ever come back as null in the middle of OnPaint. I've never had it happen in any painting of any of my forms or controls.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Try adding a toolbar to your application. In each toolbar add a button.
Set an ImageList with BitMap streams. If you close the stream see what happens.
Live Life King Size
Alomgir Miah
|
|
|
|
|
How many times do I have to tell you, I've never had a problem with it! I know about that little quirk! That's why I NEVER keep my Toolbar images in files. I keep them in Resources! I hate having open files laying around.
I keep as many images as I can in resources. I've even developed an ImageResources resource .DLL that holds my common images, including Toolbar buttons, in various sizes, masks, and transparencies. It's completely static so I don't have to instantiate the thing either.
Instead of deploying a bunch of image files along with my apps, I only deploy a sinlge .DLL. Now, all I have to do to set a Toolbar button image is:
SaveButton.Image = ImageResources.Buttons.Retrieve("Save 16x16 Trans.bmp")
Obviously, Retrieve() returns a Bitmap object. And "Look Ma!," no open file handles!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Calm down man.
There is one more way, compile the images as embedded resources into a DLL, this way you have just one DLL. Still you have to open an stream.
FYI,
when you use resource files to embed images, a stream is opened internally. If you dont trust debug for yourself.
SO I am not fighting here, I am just trying to make my point.
Live Life King Size
Alomgir Miah
|
|
|
|
|
Alomgir Miah wrote:
when you use resource files to embed images, a stream is opened internally.
Ya! Why do you think I said "no open file handles"?
You just made it sound like there was only one way to create images, using FromFile, and that EVERY Bitmap had to have an open stream associated with it. That's just not true.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
lol u r tough.
lets wrap it up.
Live Life King Size
Alomgir Miah
|
|
|
|
|
I have to simulate a communication network over a city map. with features like route feasibilty study and viewing different components of the network .. please give me some guideline in this regard. how usefull C# would be in this regard.
haroon
|
|
|
|
|
C# would be great for this. The extent that you want to do simulation for would vary based on complexity but here is my first design thought off the top of my head:
1) You have a 'controller' form which displays your network topography -- nice and graphic etc. probably using the US map as background image and controls marking the nodes and something unique for router locations etc.
2) You will need a network stub abstract class which handles the basics such as number of hops to destination, avg hop delay, bandwidth between hops etc.
3) You would inherit the abstract class defining these variables for each specific location. Each abstract class would be represented by theUI node point.
4) Included in the abastract class would be Send(), Receive(), and RoundTrip() calls that do all of the math and lag computations to handle one-way and round-trip calls into that node. (ie. sending a 10-packet message from Home() to SanFrancisco() for example.)
If each node handle computations and also inherits MyCustomControl (which is the visual stuff on the screen) then when you mouse over the control it can pull up latest transmission results (lag time, roundtrip time, simulated ping, etc.)
Sounds like a really cool project.
There are 10 kinds of people in the world.
Those that read binary...
...and those who don't.
|
|
|
|
|
Hi!
I have to read a text file which can have text in languages like french, spanish etc.
and write the text to another text file.
When i use the StreamReader and StreamWriter with Encoding as Unicode i miss all the accented characters somehow.
Help will be appreciated
Best Wishes
|
|
|
|
|
I use an italian-localized machine, and I never found this kind of problem... try to read/write the file char-by-char, using BinaryReader.ReadChar() BinaryWriter.Write((char)yourChar)). I believe this way will work.
|
|
|
|
|
I Used "Encoding.Default" while reading the file and it worked.
I like your way also and i'll be trying it too..
Thank You
Best Wishes
|
|
|
|
|
Hello,
Is there a way of placing an event inside the DataGrid on leaving a particular cell, and an event on the Column (for example TextChanged).
Mine grid is: dataGridRevenues
mine table style: styleLotYields
Thank you
|
|
|
|
|
//
//Member Variables
//
int currentGridColumn = 0;
int currentGridRow = 0;
//
//Wire Up Events
//
this.dataGridDataEntrySheet.CurrentCellChanged += new EventHandler(this.OnGridCurrentCellChanged);
foreach( DataGridTextBoxColumn dataGridTextBoxColumn in this.dataGridTableStyle.GridColumnStyles )
{
dataGridTextBoxColumn.TextBox.TextChanged += new EventHandler(this.GridTextBoxTextChanged);
}
private void OnGridCurrentCellChanged(object sender, EventArgs e)
{
DataGridCell dataGridCell = this.dataGridDataEntrySheet.CurrentCell;
//Update Member Variables
this.currentGridRow = dataGridCell.RowNumber;
this.currentGridColumn = dataGridCell.ColumnNumber;
}
private void GridTextBoxTextChanged(object sender, EventArgs e)
{
if ( this.currentGridRow = 3 && this.currentGridColumn == 5 )
{
//Do some stuff
}
else if ( ... )
{
...
}
...
}
Live Life King Size
Alomgir Miah
|
|
|
|
|
Thank you very much
It helped a lot.
Another Question: If I have a column in a datagrid, with
MapingName = "Quantity"
How can I go through each cell for this particular column.
Thank you again
|
|
|
|
|
If you want the values, then loop through the DataSource, its DataTable I guess in your case.
Please modify the code below
CurrencyManager cm = (CurrencyManager)this.BindingContext[this.dataGrid1.DataSource];
int rowCount = cm.Count;
//assumes datasource is a datatable... looping all the values
int colCount = ((DataTable)this.dataGrid1.DataSource).Columns.Count;
for(int row = 0; row < rowCount; row++)
{
for(int col = 0; col < colCount; col++)
{
object cellValue = this.dataGrid1[row, col];
Console.Write(cellValue.ToString() + " ");
}
}
Live Life King Size
Alomgir Miah
|
|
|
|
|
Thank you,
unfortunatelly the datasource is DataView, and it has no Column definition.
Thank you again.
|
|
|
|
|
It does not matter what the datasource is. CurrencyManager only expects the DataSource to implement IList interface which both DataTable and DataView does.
So please modify the code and use it.
Live Life King Size
Alomgir Miah
|
|
|
|
|
I have a little problem with a small C# Applikation that executes DTS. I don't know if this is the right Newsgroup. First of all here is what the Applikation should do.
A FileWatcherObject is monitoring a Directory for new CSV files. If there are new Files, the files will be added to an hash-table with key and filename. A timer objekt looks every 10 Seconds for Files in the hash-table and starts a DTS-Package for the first 20 Files of the hash-table. The applikation works fine, but after 2300 files i get an error from the DataPump task 80040428. This seems to be an connection problem. all other files after that error will fail too. Is it possible to change the applikation to avoid this error ? Here is the source (windows service)
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.ServiceProcess;
using System.Configuration;
using System.Runtime.InteropServices;
using Microsoft.SqlServer.DTSPkg80;
namespace xMonitoringService
{
public class xMonitoringService : System.ServiceProcess.ServiceBase
{
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.Container components = null;
public PackageClass package;
public int count;
public int gsmtcount;
public Hashtable myHT;
private System.Timers.Timer timer1;
public string serverName;
public string userName;
public string password;
public string packageName1;
public string packageName2;
public string packageName3;
public string filter1;
public string filter2;
public string filter3;
string directoryToMonitor;
FileSystemWatcher watcher;
public xMonitoringService()
{
// Dieser Aufruf ist für den Windows Komponenten-Designer erforderlich.
InitializeComponent();
// TODO: Initialisierungen nach dem Aufruf von InitComponent hinzufügen
}
// Der Haupteinstiegspunkt für den Vorgang
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
// Innerhalb eines Prozesses können mehrere Dienste ausgeführt werden. Sie können einen
// Dienst zu diesem Prozess hinzufügen, indem Sie die folgende Zeile ändern,
// um ein zweites Dienstobjekt zu erstellen. Beispiel:
//
// ServicesToRun = new System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new xMonitoringService() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InitializeComponent()
{
this.timer1 = new System.Timers.Timer();
components = new System.ComponentModel.Container();
((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();
this.timer1.Enabled = true;
this.timer1.Interval = 10000;
this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Elapsed);
this.ServiceName = "xMonitoringService";
count=0;
gsmtcount=0;
myHT = new Hashtable();
serverName = System.Configuration.ConfigurationSettings.AppSettings["serverName"];
userName = System.Configuration.ConfigurationSettings.AppSettings["userName"];
password = System.Configuration.ConfigurationSettings.AppSettings["password"];
packageName1 = System.Configuration.ConfigurationSettings.AppSettings["packageName1"];
packageName2 = System.Configuration.ConfigurationSettings.AppSettings["packageName2"];
packageName3 = System.Configuration.ConfigurationSettings.AppSettings["packageName3"];
directoryToMonitor = System.Configuration.ConfigurationSettings.AppSettings["directoryToMonitor"];
filter1 = System.Configuration.ConfigurationSettings.AppSettings["filter1"];
filter2 = System.Configuration.ConfigurationSettings.AppSettings["filter2"];
filter3 = System.Configuration.ConfigurationSettings.AppSettings["filter3"];
((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit();
}
/// <summary>
/// Die verwendeten Ressourcen bereinigen.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
/// <summary>
/// Führen Sie die Vorgänge aus, um den Dienst zu starten.
/// </summary>
protected override void OnStart(string[] args)
{
EventLog.WriteEntry("xMonitoringService","On Start");
SetupWatcher();
this.timer1.Enabled = true;
this.timer1.Start();
// TODO: Fügen Sie hier Code hinzu, um Ihren Dienst zu starten.
}
/// <summary>
/// Beenden Sie den Dienst.
/// </summary>
protected override void OnStop()
{
//Disable the watcher
watcher.EnableRaisingEvents = false;
this.timer1.Enabled = false;
this.timer1.Stop();
myHT.Clear();
myHT = null;
serverName= null;
userName= null;
password= null;
packageName1= null;
packageName2= null;
packageName3= null;
filter1= null;
filter2= null;
filter3= null;
directoryToMonitor= null;
EventLog.WriteEntry("xMonitoringService","On Stop");
// TODO: Hier Code zum Ausführen erforderlicher Löschvorgänge zum Anhalten des Dienstes einfügen.
}
private void SetupWatcher()
{
// Create a new FileSystemWatcher and set its properties.
watcher = new System.IO.FileSystemWatcher();
watcher.Path = directoryToMonitor;
//Watch for changes in FileName
watcher.NotifyFilter = NotifyFilters.FileName;
//Watch for all files.
watcher.Filter = "";
//Add event handlers.
watcher.Created += new FileSystemEventHandler(OnCreated); //Begin watching
watcher.EnableRaisingEvents = true;
}
// Define the event handlers.
public void OnCreated(object source, FileSystemEventArgs e)
{
// Specify what is done when a file is created.
//Pass in the path of the file to the DTS Package
myHT.Add(e.Name.ToString(),e.FullPath.ToString());
//ExecutePackage(e.Name,e.FullPath);
}
private void timer1_Elapsed(object sender,System.Timers.ElapsedEventArgs e)
{
IDictionaryEnumerator myEnumerator = myHT.GetEnumerator();
try
{
while ( myEnumerator.MoveNext() && count < 20)
{
if(File.Exists(myEnumerator.Value.ToString()))
{
ExecutePackage(myEnumerator.Key.ToString(),myEnumerator.Value.ToString());
count++;
myHT.Remove(myEnumerator.Key);
gsmtcount++;
}
}
if(myHT.Count == 0)
{
myHT.Clear();
myHT = new Hashtable();
}
count=0;
myEnumerator = null;
}
catch(System.Exception ex)
{
EventLog.WriteEntry("xMonitoringService","Error Message :" + ex.Message + " Stack Trace : " + ex.StackTrace + ex.Source);
}
finally
{
if(myHT.Count == 0)
{
myHT.Clear();
myHT = null;
myHT = new Hashtable();
}
myEnumerator = null;
}
}
public void ExecutePackage(string gv_fileName, string gvFullFileName)
{
try
{
package = new PackageClass();
UCOMIConnectionPointContainer CnnctPtCont = (UCOMIConnectionPointContainer) package;
UCOMIConnectionPoint CnnctPt;
PackageEventsSink PES = new PackageEventsSink ();
Guid guid = new Guid("10020605-EB1C-11CF-AE6E-00AA004A34D5"); // UUID of PackageEvents Interface
CnnctPtCont.FindConnectionPoint(ref guid, out CnnctPt);
int iCookie;
CnnctPt.Advise(PES, out iCookie);
object pVarPersistStgOfHost = null;
//Retrieve global settings from the Configuration File
string packageName="";
if (gv_fileName.IndexOf(filter1)!= -1)
{
packageName = packageName1;
}
if (gv_fileName.IndexOf(filter2)!= -1)
{
packageName = packageName2;
}
if (gv_fileName.IndexOf(filter3)!= -1)
{
packageName = packageName3;
}
if (packageName != "")
{
package.LoadFromSQLServer(serverName,userName, password,DTSSQLServerStorageFlags.DTSSQLStgFlag_Default, null, null, null, packageName, ref pVarPersistStgOfHost);
//Loop through all the Global variables and remove the
//variables that are of type string
foreach(GlobalVariable global in package.GlobalVariables)
{
if (global.Name == "gv_FileFullName")
{
package.GlobalVariables.Remove(global.Name);
}
if (global.Name == "gv_fileName")
{
package.GlobalVariables.Remove(global.Name);
}
}
//Read all the global variables that are of type string
package.GlobalVariables.AddGlobalVariable("gv_FileFullName",gvFullFileName);
package.GlobalVariables.AddGlobalVariable("gv_fileName",gv_fileName);
package.Execute();
package.UnInitialize();
package = null;
CnnctPt.Unadvise(iCookie);
}
}
catch(System.Runtime.InteropServices.COMException ex)
{
EventLog.WriteEntry("xMonitoringService","Error Code : " + ex.ErrorCode + "Error Message :" + ex.Message + " Stack Trace : " + ex.StackTrace + ex.Source);
}
catch(System.Exception ex)
{
EventLog.WriteEntry("xMonitoringService", "Error Message :" + ex.Message + " Stack Trace : " + ex.StackTrace + ex.InnerException +" "+ex.TargetSite);
}
finally
{
package.UnInitialize();
package = null;
}
}
public class PackageEventsSink : DTS.PackageEvents
{
public void OnQueryCancel(string EventSource, ref bool pbCancel)
{
EventLog.WriteEntry("xMonitoringService"," In OnQueryCancel: Event Source: " + EventSource);
pbCancel = false;
}
public void OnStart(string EventSource)
{
EventLog.WriteEntry("xMonitoringService"," In OnStart: Event Source: " + EventSource);
}
public void OnProgress(string EventSource, string ProgressDescription, int PercentComplete, int ProgressCountLow, int ProgressCountHigh)
{
EventLog.WriteEntry("xMonitoringService"," In OnProgress: Event Source: " + EventSource + " Progress Description : " + ProgressDescription +
" PercentComplete : " + PercentComplete +
" ProgressCountLow : " + ProgressCountLow +
" ProgressCountHigh : " + ProgressCountHigh);
}
public void OnError(string EventSource, int ErrorCode, string Source, string Description, string HelpFile, int HelpContext, string IDofInterfaceWithError, ref bool pbCancel)
{
EventLog.WriteEntry("xMonitoringService"," In OnError: Event Source: " + EventSource + " Error Code : " + ErrorCode.ToString() + " Source : " + Source.ToString()+
" Description : " + Description + " HelpFile : " +
HelpFile + " HelpContext : " + HelpContext +
" InterfaceError " + IDofInterfaceWithError);
pbCancel = false;
}
public void OnFinish(string EventSource)
{
EventLog.WriteEntry("xMonitoringService", "In OnFinish");
}
}
}
}
|
|
|
|
|
Hi All,
i am planning to validate a label control. i don't know how to set the ControlToValidate property of RegularExpression to a Label control
Can anyone tell me how to validate a label cotrol. is it possible?
|
|
|
|
|
What ????
Are u sure u want to validate a label ??
my point is that a label present data from the system
and if it is not valid it shouldent be there at all;
|
|
|
|
|
WHy would you ever want to? You can't get user input from it, so what's really going on?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I develop a dialog inherit ..Form and then make it to a DLL file. but I can not add this dialog's icon in toolbox, it said had none componets needed to add on the toolbox.
I change this class inherit in ..Controls or in System.ComponentModel then it can add a icon which like a gear wheel, but if it inherit by ..Form then it can't work.
My target want to build a dialog component like ..PrintDialog that it can show icon on toolbox and can drag to nonvisible component area.
I wonder if ..Form's designer prevent the inherit form component add as a control..., but why ..PrintDialog which inherit by ..Form can?
=== Game is power! ===
|
|
|
|
|
It is handled in the class attributes.
[ToolboxItem(true),
ToolboxBitmap(typeof(myControl), "myControl.bmp")]
public class myControl:UserControl
You need to have Default Namespace set to the namespace of your control and you have to have the bitmap in the root of your solution.
There are 10 kinds of people in the world.
Those that read binary...
...and those who don't.
|
|
|
|
|
At first, thanks for you help.
I do what you said, it works well, the icon that can be showed on toolbox. But when I drag the icon to the designer area and then can not see it. it can not shows on 'nonvisible component area'(a bar at the bottom of designer), say nothing of 'visible area'.
(But funny is it can be selected the component at the Property card )
=== Game is power! ===
|
|
|
|
|