|
Hi,
i use a mathod that create a control (for example textbox) and add it's to a pannel. The pannle is passed in a parameter of the method.
public static void CampoTxt(Panel frmPadre)
{
TextBox txt = new TextBox();
txt.Name = "name";
txt.Visible = true;
frmPadre.Controls.Add(txt);
}
I've manage the event ControlAdded of the pannel for modify the height of form when a visible control is added.
But every control I have added in the panel has the visible property set to false even if at the creation was set to true.
private void pnlf_ControlAdded(object sender, ControlEventArgs e)
{
...some code ....
}
Any ideas?? Thanks
|
|
|
|
|
Set a Break point at the beginning of the CampoTxt method, then step into the method and check the value of txt all the way through.
Frazzle the name say's it all
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
John F. Woods
|
|
|
|
|
It can be set to False if the control is hidden behind another control. Since, in your example, you don't set the position of the control at all, if you create a bunch of them, each will be sitting at 0,0 in the Panel, one on top of the other. Only the top control will have it's Visible property set to True.
|
|
|
|
|
In my code i set top and left property but i'm not indicate them in the example.
In addition, when the form is shown the controls are visible...
|
|
|
|
|
cursore84 wrote: but i'm not indicate them in the example.
How are we supposed to konw that if you post "fake" code?? Post the ACTUAL code you're using and things go much smoother.
cursore84 wrote: In addition, when the form is shown the controls are visible...
Then you're contradicting your own question. A much better explanation of EXACTLY what happens, when and under what circumstances is needed.
|
|
|
|
|
I reported some of the code to simplify the example, but unfortunately I left out some important information ....
But I think to have found the reason why at the event ControlAdded all the controls are invisible. I call the method "CampoTxt" before calling Form.Show () ... in this moment all the controls, including the form, have the property visible = false.
Is there a way to know if a control is visible or not at the execution of the event ControlAdded before the form is shown?
thanks
|
|
|
|
|
No. Everything will be Visible = False until the form is shown.
If you're relying on the state of controls to determine the state of your model your doing it backwards. The state data of your model should be kept in the model itself.
|
|
|
|
|
Windows App....
Problem is here "txt.Name" - Do not name your control "Name". I used to have the same problem, all control with "Name" as their names wont be visible at design time and their property will be change to false...
I remain joe!
|
|
|
|
|
Hello,
I am having some problems when running a C# application that I've written. It runs fairly smooth on a local
machine (test machine). However, when I am running this from a network drive, the responsiveness is slow. When
I click on a button that opens up a form, there is a considerable lag (5-10 seconds sometimes). Is there anything that I can do to speed this up on a network?
|
|
|
|
|
There is no generic method that will speed anything up. Code doesn't run faster or slower depending on where you ran it from. Code runs at the processor speed, not the network.
Now, any processing you have on data is remote locations or stored in files is where you'll run into problems with performance. Since we have no idea what you're code is doing when you "click a button that opens up a form", there is nothing anyone can tell you that is going to help.
We need more detail about EXACTLY what your code is doing when you run into this problem.
|
|
|
|
|
As Dave mentioned, you didn't give a lot of details so I'll take a stab in the dark and say that your "work" is probably being done on the UI thread rather than on a background worker or other type of thread. (If you have no idea what that means then you are definitely working on the UI thread.) That will kill UI performance if you start mixing long-running operations such as disk-based access or network-based access. Your UI will hang while it processes the work because there is only one guy in the room doing anything.
If this is the case, you will want to change your worker method(s) to use an async pattern so you can decouple the long-running work operations from the UI. That will keep things responsive... at least on the UI.
|
|
|
|
|
Hello everybody
I would like to cast a System.__ComObject to another type which is an interface. However, this interface is retrieved by reflection. I tried to create a generic cast method but it failed. I also tried to use TypeConverter class but it also failed. Even now, I try to use Marshal.CreateWrapperOfType but it seems to fail
Here is my code for moment
Assembly ctClientServerLib = Assembly.LoadFrom(string.Concat(bfcSetupFolder, "Interop.CtClientServerLib.dll"));
Type applicationClientClass = ctClientServerLib.GetType("CTCLIENTSERVERLib.CtApplicationClientClass");
Type ictSession = Type.GetTypeFromCLSID(new Guid("BCB06C70-AF26-11D3-8C89-00C04F517D7D"));
Type ictProtectedSession = ctClientServerLib.GetType("CTCLIENTSERVERLib.ICtProtectedSession");
Type ictSessionCtx = Type.GetTypeFromCLSID(new Guid("5F852A70-7E77-11D4-8CE1-00C04F517D7D"));
Type ictSessionClient = Type.GetTypeFromCLSID(new Guid("2C3444F9-ED6D-4700-B2EC-F665569FE830"));
Type ictProviderContainer = Type.GetTypeFromCLSID(new Guid("797BB105-AEDF-11D3-8C89-00C04F517D7D"));
Type ictProviderContainer = Type.GetTypeFromCLSID(new Guid("797BB105-AEDF-11D3-8C89-00C04F517D7D"));
object session;
object res;
res = applicationClientClass.InvokeMember("ConnectToServer", BindingFlags.InvokeMethod, System.Type.DefaultBinder, cacc, new object[] { "MyServer", "MyDataBase", new String[] { } });
session = applicationClientClass.InvokeMember("Logon", BindingFlags.InvokeMethod, System.Type.DefaultBinder, cacc, new object[] { "ADMIN", "" });
res = applicationClientClass.InvokeMember("Initialize", BindingFlags.InvokeMethod, System.Type.DefaultBinder, cacc, new object[] { session });
Type ictSession2 = ctClientServerLib.GetType("CTCLIENTSERVERLib.ICtSession");
Type ictSessionCtx2 = ctClientServerLib.GetType("CTCLIENTSERVERLib.ICtSessionCtx");
Type ictSessionClient2 = ctClientServerLib.GetType("CTCLIENTSERVERLib.ICtSessionClient");
Type ictProviderContainer2 = ctClientServerLib.GetType("CTCLIENTSERVERLib.ICtProviderContainer");
var session2 = Marshal.CreateWrapperOfType(session, ictSession);
var sessionClient = Marshal.CreateWrapperOfType(session2, ictSessionClient);
var sessionCtx = Marshal.CreateWrapperOfType(sessionClient, ictSessionCtx);
res = ictSessionCtx2.InvokeMember("SetSessionCtx", BindingFlags.InvokeMethod, System.Type.DefaultBinder, sessionCtx, new object[] { });
var providerContainer = Marshal.CreateWrapperOfType(sessionClient, ictProviderContainer);
object objectManagerClient = ictProviderContainer2.InvokeMember("get_Provider", BindingFlags.InvokeMethod, System.Type.DefaultBinder, sessionClient, new object[] { 1, -523387 });
.
Thanks for help ![Java | [Coffee]](https://www.codeproject.com/script/Forums/Images/coffee.gif)
|
|
|
|
|
Why are you doing all this manually? Can't you use tlbimp to generate an interop assembly and let Microsoft handle the plumbing?
|
|
|
|
|
Hi
Because I use API of a software and it is impossible to install 2 different versions of this software on a same machine
So some methods change depending of the software version. Maybe it is impossible to make this cast so I will find a workaround 
|
|
|
|
|
Casting unmanaged objects to managed objects is a daunting task even when things are working properly. And you aren't getting any help if the 3rd-party is changing method signatures between API revisions. That is a cardinal no-no for exactly this reason.
If I had to do this, I would use a mechanism similar to discovering and loading a plug-in at runtime. (And there are articles on CP on how to do that) I would create an interface library that defines a new interface that harmonizes the difference between the two API's. (calling it the harmonized interface) In my application, I would reference that library and use those interfaces in code. Then, I would use the tlbimp tool to generate an initial interop assembly or write my own interop assemblies that will wrap the calls to the specific API versions exposing an object that implements the harmonized interface. The connector libraries would then be responsible for the heavy lifting of marshaling the calls from the harmonized interface to the underlying API-specific objects. In most cases, this should be simply pass-thru type calls but where there are differences I would handle those in an API-specific way in each of these connector libraries.
At runtime, I would need code which detects the correct version of the outside API and loads the appropriate connector library instantiating my interop class(es). Since they implement the common, harmonized interface, my app code would be consistent and the specifics of the underlying API differences are handled in the correct connector library. Where needed, I would use the underlying API version I detected to call (or not call) certain methods on the harmonized interface as appropriate.
The advantage of this approach is that when the API vendor screws you again with a new version that breaks the current API, you can simply write a new connector library and everything continues to work. If new functionality is added, expand the harmonized interface, implement those new methods in ALL of the connectors, but throw exceptions in the ones where the underlying API doesn't support the new functionality.
|
|
|
|
|
It's a terrible way to go, but I do not see a better one.
Using the dynamic keyword in a common base class for some of the types of ThridParty may help reduce coding - but can lead to problems with some interfaces.
|
|
|
|
|
I am trying to develoop an application in c# using Aforge.dll but please anyone give me some idea how to make object (edge detect) through webcam so that i can find approx origina length and breadth
|
|
|
|
|
|
hi , im working on a website and i want to let the user add their img for their account .
i know one way for adding img into the sqldatabase and its the regular one to using the file stream and then sql parameter , i know that way so far .
but do we have any other way for adding img into sql database without using the sql parameter .
and truly why i should define a sql parameter . is it really necessary to define a sql paramater then just define the type and set it to img and do all of that things ?
|
|
|
|
|
mohammadkaab wrote: is it really necessary to define a sql paramater
Yes. Concatenating the value into the SQL-string is insecure. Hence, all queries with parameters.
Why is it a problem? Don't tell me that it's "too much typing".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
No , absolutly not , when i want to insert some data to the database the only thing i do is to use command text and then do the rest . but i though , inserting img into the database is also like inserting string.
ty anyway.
|
|
|
|
|
Any variable inserted should be using a parameter. Also strings.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
con.open();
com.connection = con;
com.commandtext = @"insert into table1 (name,family,id)values('"+textbox1.text+"','"+textbox2.text+"','"+textbox3.text+"')";
com.executenonequery();
con.close();
im using this type of inserting without of sql parameter , so ? is it wrong ?
|
|
|
|
|
mohammadkaab wrote: im using this type of inserting without of sql parameter , so ? is it wrong ?
Yes/no. It's not "wrong" in the sense that it will not compile or run, but it is wrong in the sense of being secure. It's recommended to use parameters to prevent SQL-injection attacks. Concatenating strings is heavily frowned upon, the more there it gives one a headache with formatting dates in different parts of the world.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Try typing the following in textbox3 :
Robert');drop table table1;--
Your query now becomes:
insert into table1 (name,family,id)values('me','Corleone','Robert');drop table table1;
That's two queries - one to insert a record, and one to drop the table. The -- comments out the rest of the query.
Congratulations - you've just met little Bobby Tables[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|