Can't figure out how to do this with ms .net.
Previous you just invoked the class wizard.
Any ideas?
1. associated namespaces do not comprise enclosing classes of the base class
2. Access methods in View class from toolbar class
I have a custom toolbar class that I wrote which works fine, but I would like to call a function from my FormView class depending on the value in the combobox of my toolbar. I am not exactly sure how to access the FormView from my toolbar class. Z.K.
3. how to get the class object associate with a window
4. Associate WPF Graphic with a Class
Hmm, instead of drawing the lines and whatnot, have you considered
making the lines (with the associated elements) and rectangles UIElements
themselves? They would have their own dependency properties, etc, etc, and
then you would add them to the canvas.
Then, in relation to your class, you could just have it listen to the
event handlers for the dependency properties you expose and do something
when the value changes.
For example, for a Line class, you would have a Point1 dependency
property and a Point2 dependency property (maybe, it's up to you) which
expose the endpoints of the line. Then, you could just register to receive
change notifications in your class that you want to receive updates.
--
- Nicholas Paldino [.NET/C# MVP]
- XXXX@XXXXX.COM
"Wonko the Sane" <Wonko the XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...
> Hi All,
>
> I have the following (much-simplified) situation. I have a class, part of
> which involves drawing graphics on a Canvas. I may have a number of
> instances of these graphics, which may include a line, two rectangles used
> as
> endpoints, and perhaps a label for the line.
>
> I want to somehow later associate a graphic on the canvas with an instance
> of the class. For instance, if the user selects an endpoint and drags it,
> I
> want to resize the line, and perhaps update some information in a database
> based on that resize.
>
> I'm just looking for a graceful way to do this. I have a solution, but it
> seems inelegant. Any advice or a pointer to an example would be
> appreciated...
>
> Thanks.
5. Associate an attribute with a type other than class definition - CSharp/C#
6. associating a custom class to a resource
Let's say you have your own collection of customized common controls, all derived from the original ones. So, CustomEdit derived from CEdit, CustomButton derived from CButton, etc. Now, let's say you only provide clients with the headers of your classes, a lib file and a DLL containing the implementation. When creating an edit box in the resource editor, how can you associate it with CustomEdit instead of CEdit? The only way I am able to do this right now is to first associate it with CEdit, and then go make the change in the code to CustomEdit. In other words, I can't see the CustomEdit class in the classwizard when I have to choose a class to bind with the edit box resource, even if I include the header file in the projet. Is there something that can be done to add these classes to a common collection known to the resource editor? Thank you.
7. class derived from CFormView is not associated with dialog
I requested help with some code in a previous thread, as requested in the
feedback, below are the .cpp and .h files for all three classes (Entry, Race
and Yacht). The three classes are all ossociated through pointers. Objects
are created and called in a main as follows: (I apologise for the excess of
white space, unfortunately this occurs when I cut and paste from my
compiler)
Race r1(1, "23/12/03");
Race r2(2, "24/12/03");
Yacht y1("The Bounty", "William Bligh");
Yacht y2("The Hilda", "Some bloke");
Yacht y3("The Mary Celeste", "Benjamin Briggs");
Yacht y4("Speedy", "Some other bloke");
r1.enter_race (&y1,3, "22:30");
r1.enter_race (&y2,2, "22:00");
r1.enter_race (&y3,1, "21:00");
r2.enter_race (&y4,1, "15:00");
cout << r1 << endl;
cout << r2 << endl;
r1.display_entries ();
r2.display_entries ();
r1.winner ();
The classes seem to compile and link correctly; however, the Race::winner
function does not work and I'm not sure on how to code the Yacht::add_entry
function, comments of what this should do are in the body of the add_entry
function, this also needs to be called from the Race::enter_race function,
as commented within this function.
I realise my solution below could be refined somewhat; however, I'm still
very much learning and would greatly appreciate help on getting this project
to work.
Thanks
//Entry.cpp
#include <iostream>
#include <string>
#include "Entry.h"
#include "Race.h"
#include "Yacht.h"
using namespace std;
//Construct an Entry
Entry::Entry (Race* r, Yacht* y, int pl, string ti)
{
which = r;
what = y;
place = pl;
time = ti;
}
//Access functions
int Entry::getPlace () const
{
return place;
}
string Entry::getTime () const
{
return time;
}
Race* Entry::getRace () const
{
return which;
}
Yacht* Entry::getYacht () const
{
return what;
}
//Overload of operator<< for output of an Entry
ostream& operator<< (ostream& out, const Entry& e)
{
Yacht* y = e.what;
Race* r = e.which;
out << endl << "Yacht : " << *y << endl
<< "Race : " ; r->Show();
out << "Finish Place : " << e.place << endl
<< "Finish Time : " << e.time << endl << endl;
return out;
}
//Entry.h
#ifndef ENTRY_H
#define ENTRY_H
#include <iostream> // for standard i/o
#include <string> // for string manipulation
using std::ostream;
using std::string;
class Yacht;
class Race;
//Details of race entries
class Entry
{
friend ostream& operator<< (ostream&, const Entry&);
public:
//constructor
Entry (Race* r=NULL, Yacht* y=NULL, int pl=0, string ti="");
//access functions
int getPlace () const; //Yacht placing
string getTime () const; //Yacht finish time
Race* getRace () const; //Related race object
Yacht* getYacht () const; //Related yacht object
private:
//Attributes to implement the relationship
Race* which; //Which race
Yacht* what; //What yacht
//Attributes of the association
int place;
string time;
};
ostream& operator<< (ostream&, const Entry&);
#endif
//Race.cpp
#include <string>
#include "Race.h"
#include "Entry.h"
#include "Yacht.h"
using namespace std;
//Construct a race
Race::Race (int n, string d)
{
number = n;
date = d;
nEntries = 0;
for (int j=0; j<MAX_ENTRIES; j++)
entries[j] = NULL;
}
//Enter a race
void Race::enter_race (Yacht* y, int pl, string ti)
{
if (nEntries<MAX_ENTRIES)
{
Entry* e = new Entry (this,y,pl,ti);
entries[nEntries++] = e;
//y->add_entry; //need to call the Yacht::add_entry function here
}
else cout << "Too many entries" << endl;
}
//Find an entry object(s)
void Race::display_entries (ostream& out) const
{
if (nEntries == 0)
out << "No entries" << endl;
else
{
cout << "Details of Yachts entered into the requested race:" <<endl << endl;
for (int i=0; i<nEntries; i++)
out << *(entries[i]);
}
}
//Find the winner
void Race::winner (ostream& out) const
{
//int i;
Entry* e = NULL;
if (nEntries == 0)
{
out << "No entries" << endl;
}
else
{
for (int i=0; i<nEntries; i++)
{
e = entries[i];
if (e)
if (e->getPlace() == 1)
{
out << e;
}
else
{
out << "No winner was found in this race" << endl;
}
}
}
}
//Access functions
int Race::getNumber (void) const
{
return number;
}
string Race::getDate (void) const
{
return date;
}
//Output functions
//Print Race info
void Race::Show (ostream& out) const
{
out << "Race Number : " << number << endl
<< "Race Date : " << date << endl;
}
ostream& operator<< (ostream& out, const Race& r)
{
r.Show (out);
if (r.nEntries == 0)
out << "No entries" << endl;
else
{
for (int i=0; i<r.nEntries; i++)
out << *(r.entries[i]);
}
return out;
}
//Race.h
#ifndef RACE_H
#define RACE_H
#include <iostream> // for standard i/o
#include <string> // for string manipulation
using std::ostream;
using std::cout;
#include "Entry.h"
#include "Yacht.h"
const int MAX_ENTRIES = 20;
//Details of races
class Race
{
friend ostream& operator<< (ostream&, const Race&);
public:
//constructor
Race ( int n=0, string d="");
void enter_race (Yacht*,int, string);
void Show (ostream& out=cout) const;
void display_entries (ostream& out=cout) const;
void winner (ostream& out=cout) const;
//member function prototypes
int getNumber() const;
string getDate() const;
private:
//Attributes of yachts
int number;
string date;
//Attributes for association
Entry* entries[MAX_ENTRIES];
int nEntries;
};
ostream& operator<< (ostream&, const Race&);
#endif
//Yacht.cpp
#include <iostream>
#include <string>
#include "Yacht.h"
using namespace std;
//Construct a yacht
Yacht::Yacht (string n, string c)
{
name = n;
captain = c;
}
//Enter a race
void Yacht::add_entry ()
{
//Add_entry just needs to be given a pointer to the
//just-created new entry as its sole argument, and
//it should just store that pointer in the next unused
//location in an array of pointers to entries (mirroring
//the array of pointers to entries in the Race class).
//I have not yet declared the array of pointers in the
//Yacht class - it needs to be added and I'm not sure on
//how to do this correctly
}
//Access functions
string Yacht::getName (void) const
{
return name;
}
string Yacht::getCaptain (void) const
{
return captain;
}
//Overload of operator<< for output of a yacht
ostream& operator<< (ostream& out, const Yacht& y)
{
out << y.name << " (Captain: " << y.captain << ")";
return out;
}
//Yacht.h
#ifndef YACHT_H
#define YACHT_H
#include <iostream> // for standard i/o
#include <string> // for string manipulation
#include "Entry.h"
#include "Race.h"
using namespace std;
//Details of yachts
class Yacht
{
friend ostream& operator<< (ostream&, const Yacht&);
void add_entry ();
public:
//constructor
Yacht (string n="", string c="");
//member function prototypes
string getName() const;
string getCaptain() const;
private:
//Attributes of yachts
string name;
string captain;
};
ostream& operator<< (ostream&, const Yacht&);
#endif