I need to programitically add tabs to a Silver.UI toolbox after load, and after I add the tabs and call refresh, it still does not show them. But for some reason, when I put the code in load, it works! Here's my code:
//Load the objects into the desinger
DesignDeserializer deserializer = new DesignDeserializer();
deserializer.load();
public void createTab(string title)
{
ToolBoxTab tab = new ToolBoxTab(title, 1);
objectBox.AddTab(tab);
objectBox.RefreshTabs();
}
Here's my DesignDeserializer:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Silver.UI;
namespace EmuGUI
{
class DesignDeserializer : main
{
public void load()
{
//Send to create the tabs...
createTab("foo");
}
}
}
It does not give me any errors...
Related
I've been creating an application for university coursework, using Visual Studio Forms, and I was trying to launch the form I've made to check it's connecting to the database behind it, but it won't accept the name of the form as legitimate. I have no idea why, as it is appearing in the Solution Explorer.
This is the code for the program.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FoxhillCustomer
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmViewEditStaff());
}
}
}
This is the code for the frmViewEditStaff.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace FoxhillViewEditStaff
{
public partial class frmViewEditStaff : Form
{
SqlDataAdapter daViewEditStaff;
DataSet dsFoxhillDentistryFinal = new DataSet();
SqlCommandBuilder cmdBViewEditStaff;
DataRow drViewEditStaff;
String connStr, sqlViewEditStaff;
int selectedTab = 0;
bool staffSelected = false;
int staffNoSelected = 0;
public frmViewEditStaff()
{
InitializeComponent();
}
private void frmViewEditStaff_Load(object sender, EventArgs e)
{
connStr = #"Data Source = .\sqlexpress; Initial Catalog = InTheDogHouse; Integrated Security = true";
sqlViewEditStaff = #"select * from Staff";
daViewEditStaff = new SqlDataAdapter(sqlViewEditStaff, connStr);
cmdBViewEditStaff = new SqlCommandBuilder(daViewEditStaff);
daViewEditStaff.FillSchema(dsFoxhillDentistryFinal, SchemaType.Source, "ViewEditStaff");
daViewEditStaff.Fill(dsFoxhillDentistryFinal, "ViewEditStaff");
dgvStaff.DataSource = dsFoxhillDentistryFinal.Tables["Staff"];
dgvStaff.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
tabStaff.SelectedIndex = 1;
tabStaff.SelectedIndex = 0;
}
}
}
Your form is in a namespace of FoxhillViewEditStaff. Your Program class is in a namespace of FoxhillCustomer, and you don't have a using directive for the FoxhillViewEditStaff namespace.
I'd strongly advise you to:
Use a single namespace for all the classes in your project
Rename all your forms to follow normal .NET naming conventions, to make the code clearer
You could just add a using directive, but it would be more sensible to just put the classes into the same namespace, IMO.
I have two solutions TranferService and Sender. TranferService has WCF service and IISHost to host that service. In Sender solution i have windows forms application. In that form i used button to browse and select file, text box to display selected file path, and another button(Send) to transfer that file through WCF service. But i am unable to access textbox value in the transfer solution. it shows"the name does not exist in the current context".
Code for TransferService
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace TransferService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "TransferService" in both code and config file together.
public class TransferService : ITransferService
{
public File DownloadDocument()
{
File file = new File();
String path = txtSelectFilePath.Text;
file.Content = System.IO.File.ReadAllBytes(#path);
//file.Name = "ImagingDevices.exe";
return file;
}
}
}
I am getting error on this line
String path = txtSelectFilePath.Text;
code for form.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Sender
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Browse_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
txtSelectFilePath.Text = openFileDialog1.FileName;
}
}
private void Send_Click(object sender, EventArgs e)
{
TransferService.TransferServiceClient client = new TransferService.TransferServiceClient();
TransferService.File file = client.DownloadDocument();
System.IO.File.WriteAllBytes(#"C:\DownloadedFiles\" + file.Name, file.Content);
MessageBox.Show(file.Name + " is downloaded");
}
}
}
Code for ITransferService.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace TransferService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "ITransferService" in both code and config file together.
[ServiceContract]
public interface ITransferService
{
[OperationContract]
File DownloadDocument();
}
[DataContract]
public class File
{
[DataMember]
public string Name { get; set; }
[DataMember]
public byte[] Content { get; set; }
}
}
Thanx a lot in advance..........
Then create a constructor to your class that receives a path as string something like this:
public class TransferService : ITransferService
{
private string _path;
public TransferService(string path) {
_path = path
}
public File DownloadDocument()
{
File file = new File();
//String path = txtSelectFilePath.Text;
file.Content = System.IO.File.ReadAllBytes(_path);
//file.Name = "ImagingDevices.exe";
return file;
}
}
and then on form.cs
TransferService.TransferServiceClient client = new TransferService.TransferServiceClient(txtSelectFilePath.Text);
I need your help with c# and some graphic issues: I'm developing a very simple application. There is a unique form called DeltaPregView, a controller for the form called DeltaPregController and a class that contains the Main of the project:
Main Class:
using System;
using System.Linq;
using System.Collections.Generic;
using System.Windows.Forms;
namespace deltaPreg
{
static class Program
{
[MTAThread]
static void Main()
{
//create the view
DeltaPregView view = new DeltaPregView();
//link the view to the APP
Application.Run(view);
//initialize the controller of the APP
DeltaPregController controller = new DeltaPregController(view);
}
}
}
View for the class:
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace deltaPreg
{
public partial class DeltaPregView : Form
{
public DeltaPregView()
{
InitializeComponent();
}
public void init()
{
prova.Visible = false;
}
}
}
and the Controller for the view:
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
namespace deltaPreg
{
class DeltaPregController
{
#region variables
private DeltaPregView view;
#endregion
public DeltaPregController(DeltaPregView view)
{
this.view = view;
//start the reading process
start();
}
private void start()
{
view.init();
}
}
}
I would like to hide the button called "prova", but nothing changes in my program. I'm a newbie in the winforms management, thank you in advance.
The problem is that you print the form before you call the init function in DeltaPregView.
One way to solve this is by replacing those lines:
//link the view to the APP
Application.Run(view);
//initialize the controller of the APP
DeltaPregController controller = new DeltaPregController(view);
To:
//initialize the controller of the APP
DeltaPregController controller = new DeltaPregController(view);
//link the view to the APP
Application.Run(view);
I am using WCF service to display data into gridview but it not properly displaying(Columns are displaying out of order)
Following is my seperate class file containing properties to be added to IList object
Code:
Class1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ServiceTest
{
public class Class1
{
public int index { get; set; }
public string name { get; set; }
public int id { get; set; }
}
}
This is Service interface
IService1.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Collections;
namespace ServiceTest
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
[OperationContract]
IList<Class1> GetD();
}
}
This is service class that implements IService.cs
Service1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Collections;
namespace ServiceTest
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
public class Service1 : IService1
{
public IList<Class1> GetD()
{
IList<Class1> lst = new List<Class1>();
for (int i = 0; i < 50; i++)
{
Class1 c = new Class1();
c.index = i;
c.name = "Madhavi " + i;
c.id = i + 1;
lst.Add(c);
}
return lst;
}
}
}
Below is my consumer code having one gridview databound control.
And consumer code
protected void Page_Load(object sender, EventArgs e)
{
//IList i = new ArrayList();
Service1Client s = new Service1Client();
// i = s.GetD();
GridView1.DataSource = s.GetD();
GridView1.DataBind();
}
Sounds as if you have AutoGenerateColumns set to true for the GridView1. You can instead try explicitly specifying the columns in the .aspx file in the order that you would like these columns to appear and bind each column with the appropriate field from the Datasource.
<asp:GridView runat="server" id="GridView1">
<Columns>
</Columns>
</GridView>
I'm creating a custom C# control (form's title bar). One form can have only one title bar, and that's why i'm wondering something: When user (programmer) adds my title bar to his form, is there ANY way i can check if ParentForm already contains my title bar, and if so can i cancel adding another instance of my control?
I know how to perform check to see types of controls ParentForm contains, but what event is raised when my control is dropped from toolbox to form, and how to "cancel" layout of my control if necessary?
You should read in-depth about the designer technologies available in .NET, because these are not what I would call production-ready examples. However, this gives you a solid start and both code snippets do what you are asking.
For design time, you can override the designer site in your control and do the following:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel.Design;
using System.Diagnostics;
namespace WindowsFormsControlLibrary1 {
public partial class DebugControl : UserControl {
public DebugControl() {
InitializeComponent();
}
public override ISite Site
{
get
{
return base.Site;
}
set
{
base.Site = value;
IComponentChangeService service = (IComponentChangeService)GetService(typeof(IComponentChangeService));
service.ComponentAdding += (sender, e) => {
IDesignerHost host = (IDesignerHost)value.Container;
Component component = (Component)host.RootComponent;
if (component as Form != null)
{
Form form = (Form)component;
foreach (Control c in form.Controls)
{
if (c.GetType() == this.GetType())
{
throw new System.ArgumentException("You cannot add two of these controls to a form!");
}
}
}
};
}
}
}
}
For runtime in your form you can override OnControlAdded and do the following:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using WindowsFormsControlLibrary1;
namespace WindowsFormsApplication1 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
protected override void OnShown(EventArgs e)
{
Controls.Add(new DebugControl());
}
protected override void OnControlAdded(ControlEventArgs e)
{
base.OnControlAdded(e);
if (e.Control.GetType() == typeof(DebugControl))
{
int count = 0;
foreach (Control c in Controls)
{
if (c is DebugControl)
{
count++;
}
}
if (count > 1)
{
Controls.Remove(e.Control);
Debug.Assert(false, "Cannot add two of these controls!");
}
}
}
}
}
There are more than one way to do this, but these are rough examples, mind you. Read up on design-time support that the .NET framework, it is very rich and there are extensive documentation on it. Another method is to implement custom designers and implement CanBeParentedTo and CanParent, but mind you CanBeParentedTo is not called when your control is drug from the ToolBox to your form.
You may use Controls collection of the active form.
Handle the ParentChanged event, check the parent's Controls, and throw an exception if necessary.