|
Sorry for the delay. I was going to answer you sooner, but I fell while the putting children to sleep
One change I had in mind is that the list base operation is going to be slow. So if we're targeting for 3.5 I'd suggest that we use this kind of approach for notifying the subscribers.
private System.Collections.Generic.HashSet< Subscriber > _subsribers = new HashSet<subscriber>();
...
public void Notify< T >(T instance) {
var subscribers = from item in this._subsribers
where item.Type.Equals(typeof(T))
select item;
foreach (Subscriber subscriber in subscribers) {
subscriber.GetNotifyDelegate< T >()(instance);
}
}</subscriber>
That's based on my version of the singleton so the Notify signature is different from yours but the contents should quite same.
What do you think if we would use another way to communicate? I'm afraid we'll flood the forum at certain point and it's also a bit difficult to change code like this. Perhaps using email so we could transfer the entire projects?
|
|
|
|
|
Mika Wendelius wrote: Perhaps using email so we could transfer the entire projects
I agree.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
modified on Friday, January 16, 2009 7:57 AM
|
|
|
|
|
Okay, I got the address so you can remove it from the post. I'll send you a message in the evening.
|
|
|
|
|
I'm developing a drawing app and I'm using a UserControl as a basis to paint on. Everything is working fine but I'm wanting to keep the current view centered when a ZoomIn/ZoomOut operation occurs. For instance, if the user is working on a Rectangle and wants to zoom in closer, he would want the rectangle to stay in focus instead of scaling out of bounds. In my initial test, I can't figure out how microsoft calculates the position of the scrollbar handle and therefore I can't perform any centering algorithms. I don't want to center the whole document, just the area where the user is currently scrolled to.
Any help would be greatly appreciated!!
Richard
My code this week has no errors. But it's Monday morning and I haven't got out of bed.
|
|
|
|
|
Hi Richard,
I haven't used it myself yet, but it seems to me the documentation on ScrollableControl.AutoScrollPosition explains rather well how scrolling is supposed to work.
This is what I would try:
assume control size is (2w,2h) and current autoscrollposition is (asx,asy)
center point is (w,h) relative to the topleft corner of the visible control, hence (asx+w,asy+h) logically;
when the zoom factor changes by a factor of zf (zoomnew/zoomold), new logical position of center point would be (zf*(asxnew+w),zf*(asynew+h)), but relative position should remain (w,h), hence:
asxnew=(asx+w)/zf-w
asynew=(asy+h)/zf-h
obviously boundary tests would be necessary to prevent "overscrolling" (showing stuff that lies outside
the drawing) if possible.
I hope I got this right and made this somewhat clear...
Luc Pattyn [Forum Guidelines] [My Articles]
I use ListBoxes for line-oriented text, and PictureBoxes for pictures, not drawings.
modified on Friday, June 10, 2011 12:33 PM
|
|
|
|
|
Thanks for the info. I haven't tried it yet but it sounds logical.
My code this week has no errors. But it's Monday morning and I haven't got out of bed.
|
|
|
|
|
Hi .. Everyone
Im trying to a simple address lookup using winform. What im trying to do is have a text box were a user can type in their PostCode/zip code and it will do a simple database(Sql) lookup but you do not have to type in your full postcode/ zip i can b just the first few characters and it still should find the full address information ..
Can any one help me with this because im stuck on this
|
|
|
|
|
Well did you try anything yet? Are you creating this database? Let's see some code, what do you have done so far, which part are you specifically stuck on?
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace AddressFinder
{
public partial class AddressSelecter : Form
{
private static readonly object EventClose = new object();
public event EventHandler OnClose
{
add
{
Events.AddHandler(EventClose,value);
}
remove
{
Events.RemoveHandler(EventClose,value);
}
}
public virtual void OnCloseEvent(EventArgs e)
{
EventHandler handler = (EventHandler) Events[EventClose];
if(handler!=null)
{
handler(this, e);
}
}
public AddressSelecter()
{
InitializeComponent();
}
private string buildingNo;
public string BuildingNo
{
get { return buildingNo; }
set { buildingNo = value; }
}
private string street;
public string Street
{
get { return street; }
set { street = value; }
}
private string city;
public string City
{
get { return city; }
set { city = value; }
}
private string country;
public string Country
{
get { return country; }
set { country = value; }
}
public string PostCode
{
get { return txtPostCode.Text; }
set { txtPostCode.Text = value; }
}
private void button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand(@"select
b.buildingId,
b.buildingname,
s.streetname,
c.cityname
from
zipcode z
inner join city c on z.CityID = c.CityID
inner join building b on z.zipcodeid = b.zipcodeid
inner join street s on z.zipcodeid = s.zipcodeid
where z.zipcode = @postcode;");
cmd.Parameters.AddWithValue("postcode", txtPostCode.Text);
SqlDataReader reader = Read(cmd);
if (reader.HasRows)
{
while (reader.Read())
{
ItemObject item = new ItemObject();
item.Key =
string.Format("{0}, {1}, {2}", reader.GetString(1), reader.GetString(2), reader.GetString(3));
item.ValueOfKey = reader.GetInt64(0).ToString();
listBox1.Items.Add(item);
}
}
}
private void button2_Click(object sender, EventArgs e)
{
ItemObject selectedObject = (ItemObject)listBox1.SelectedItem;
lblBuilding.Text = selectedObject.ToString();
SqlCommand cmd = new SqlCommand(@"select
b.buildingname,
s.streetname,
c.cityname,
cntry.countryname
from
zipcode z
inner join city c on z.CityID = c.CityID
inner join building b on z.zipcodeid = b.zipcodeid
inner join street s on z.zipcodeid = s.zipcodeid
inner join country cntry on z.countryid = cntry.countryid
where z.zipcode = @postcode and b.buildingId = @buildingId");
cmd.Parameters.AddWithValue("postcode", txtPostCode.Text);
cmd.Parameters.AddWithValue("buildingId", selectedObject.ValueOfKey);
SqlDataReader reader = Read(cmd);
if (reader.HasRows)
{
reader.Read();
BuildingNo = reader.GetString(0);
Street = reader.GetString(1);
City = reader.GetString(2);
Country = reader.GetString(3);
}
lblBuilding.Text = BuildingNo + " " + Street;
lblCity.Text = City;
lblCountry.Text = Country;
}
private static SqlDataReader Read(SqlCommand cmd)
{
SqlConnection connection = new SqlConnection("Data Source=localhost;Database=Geo;Integrated Security=SSPI");
connection.Open();
cmd.Connection = connection;
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
return reader;
}
private void btnOk_Click(object sender, EventArgs e)
{
this.Hide();
OnCloseEvent(e);
}
}
public class ItemObject
{
private string key;
private object valueOfKey;
/// <summary>
/// Overloaded constructor.
/// </summary>
/// <param name="key">Key of object.</param>
/// <param name="valueOfKey">Value of object.</param>
public ItemObject(string key, object valueOfKey)
{
this.key = key;
this.valueOfKey = valueOfKey;
}
/// <summary>
/// Default constructor
/// </summary>
public ItemObject()
{
key = string.Empty;
valueOfKey = string.Empty;
}
///<summary>
///Returns a <see cref="T:System.String"></see> that represents the current
///<see cref="T:System.Object">
/// </see>.
///</summary>
///
///<returns>
///A <see cref="T:System.String"></see> that represents the current
///<see cref="T:System.Object">
/// </see>.
///</returns>
public override string ToString()
{
return key;
}
///<summary>
///Serves as a hash function for a particular type.
///</summary>
///
///<returns>
///A hash code for the current <see cref="T:System.Object"></see>.
///</returns>
public override int GetHashCode()
{
return ToString().GetHashCode();
}
/// <summary>
/// Gets or sets Key of object.
/// </summary>
public string Key
{
get { return key; }
set { key = value; }
}
/// <summary>
/// Gets or sets Value of object.
/// </summary>
public object ValueOfKey
{
get { return valueOfKey; }
set { valueOfKey = value; }
}
}
}
I have created the database an every thing. At the moment you have to type in the full post code for it to populate. i want so that you do not have to type in the full post code E.G if the full post code is IG6 6AF you should be able to type any part of it and still be able to search and find the address..
i hope you can help
Thank You
|
|
|
|
|
Use autocomplete on your textbox and bind your postal codes as a datasource, or you can use wildcards for your sql statement albeit you will get multiple results if a search overlaps 2 or more results. I would use wildcards.
|
|
|
|
|
Im sorry to bother you .. but do you think that looking at my code is it very good or is no that good .. becuase i have only just started C# 2 weeks ago and i tought my self .. I dont know how to use wildcard .. if they is an example i can follow i would be happy
|
|
|
|
|
If youre using access the wildcard is * or if you are using mssql or mysql the wildcard is %
For instance you have a table called names with Lesley, Leyla and mike if you do select * from names where name LIKE e% you will get results of Lesley and Leyla.
You are off to a good start for 2 weeks, look up on good practices and naming conventions.
Edit; its no bother, you are making an effort and thats what counts.
|
|
|
|
|
How do i increase the size of the panel dynamically at runtime
|
|
|
|
|
Set the Width and Height ?
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Calculate the height of each control contained within the panel using a loop, and set the panel height to that number. Do the same for width if you need to resize the width as well.
|
|
|
|
|
I get string in UTF-8 format, and when I insert this string to DB it's appears as ??????
I know that string are in UTF-16 and I need to convert it to UTF-8.
I search in web to find good example but i don't find.
Someone can post some code or link how to convert simple string to string in UTF-8 ?
this is example of string in UTF-8 that i want to insert to DB.
Str= "œæÆ à â ç é è ê ë î ï ô û ù ü ÿ ";
|
|
|
|
|
Sorry, I'm a little confused by the explanation. Can you put the DataType of the Column from the database table (varchar, nvarchar, char, nchar, etc.)? Also, I'm confused about whether you're taking a UTF-8 string and converting to UTF-16 or vice-versa.
Keep It Simple Stupid! (KISS)
|
|
|
|
|
O.k :
the data type of the column is varchar(500).
And about UTF-16:
I just search in web and found that when I define string Str, the default
Encoding to Str is UTF-16. am I wrong ??
So- the option to change the column data type to Nvarchar is irrelevant
Because we have a big DB, so changing data type will cause to multiple the DB size....
I need to found a way to insert Str= "œæÆ à â ç é è ê ë î ï ô û ù ü ÿ ";
Without to change the data type.
|
|
|
|
|
A string is neither in UTF-8 or UTF-16, a string is just a string. When you encode a string as UTF-8 or UTF-16 you get a byte array. The memory representation for a string happens to be the same as UTF-16, but a string is not the same thing as a byte array.
If you want to store the string encoded as UTF-8 in the database you can't store it in a text field, you would have to use an image field.
I don't think that you really want to store the string as UTF-8, I think that you want to store it as unicode text, i.e. an nvarchar or ntext field.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I'm looking for the way to create a class that can be used like a DataTable. I just want to have the dynamic rows and columns (no need to have AcceptChanges or Rollback or etc).. but that class should be able to bind with DataGrid. Thanks.
|
|
|
|
|
Michael Sync wrote: I'm looking for the way to create a class that can be used like a DataTable. I just want to have the dynamic rows and columns (no need to have AcceptChanges or Rollback or etc).. but that class should be able to bind with DataGrid.
You can try inheriting the DataTable to write one...?
But what's wrong using the DataTable directly... as long as you want to keep it binded with a DataSet..?
Moim Hossain
R&D Project Manager
BlueCielo ECM Solutions BV
|
|
|
|
|
Thanks.
Actually, I'm using Prism (CompositeWPF) version 2 with multi-targeting feature. Once we crate a class, we have to think about how to use in both WPF and Silverlight. DataTable or DataSet or etc is not available in Silverlight. So, I'm thinking to create very small version of DataTable that we can add/remove the column with Columns name. And we want to bind it with DataGird.
|
|
|
|
|
Michael Sync wrote: I'm thinking to create very small version of DataTable that we can add/remove the column with Columns name
Well, in that case, you might need to write a simple and small version of DataTable for ur ViewModel. You can make use of reflector to get more idea about the .net implementation of DataTable.
One suggestion though, if the binding is the only concern, you could actually define any .net enumerable properties ..I guess?
Moim Hossain
R&D Project Manager
BlueCielo ECM Solutions BV
|
|
|
|
|
Yes. I'm thinking to have a class like below.
class MyDataRow{
}
class MyDataColumn{
}
class MyDataTable{
List<MyDataRow> Rows{}
List<MyDataColumn> Columns{}
}
but
1) I'm not sure whether how I can make my class as a binding class.
eg.
VM
public MyDataTable MyData{
set{..
....PropertyChanged(..)....
}
get{..}
}
<DataGrid ItemSource="{Binding MyData}" />
2. How can I know whether new column or row has been added to now??
E.g.
MyDataTable mydata = new MyDataTable();
mydata.Columns.Add(new MyDataColumn() { Name = "A" });
mydata.Columns.Add(new MyDataColumn() { Name = "B" });
mydata.Columns.Add(new MyDataColumn() { Name = "C" });
Thanks in advance.
|
|
|
|
|