Multiple picture boxes in multiple tab pages - visual-studio-2010

I have one tabcontrol on a form with two tabpages and two picture boxes in each. I use rightclick to open a context menu for selecting a file to display in each picturebox. When I do it with one picturebox it is OK. However, after selecting a file for other picturebox fails with an exception "Parameter not valid".
Basically, I do this:
System::Void DPrint::Form1::toolStripMenuItem1_Click(System::Object^ sender, System::EventArgs^ e)
{
if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
if (imgToDisplay != nullptr)
{
delete imgToDisplay;
}
PictureBox^ MyPictureBox = safe_cast<PictureBox^>(this->contextMenuStrip2->SourceControl);
imgToDisplay = gcnew System::Drawing::Bitmap(this->openFileDialog1->FileName);
MyPictureBox->Image = safe_cast<Image^>(imgToDisplay);
}
}
Any idea what is wrong? Thank you so much.

Solved.
I was deleting the last image to be displayed so I have removed an if statement
and everything works. Thank you.

Related

Windows Form Listview is not visually showing selected items

We have a tool that is being integrated into our application. We have some strict borders around us too in that we cannot modify the application except for our extensions. I have searched here, I've searched the internet, but cannot find any postings about this problem.
I have a Windows Form that contains a ListView and our user requires we create a checkbox to Select/Deselect all. I have the event handler for when the check box state changes and call the routine to set everything to Selected.
private void SelectAllEventHandler(object sender, EventArgs e)
{
ChangeState(RadCapListView, SelectAllRadcap.Checked);
}
private void ChangeState(SWF.ListView control, bool state)
{
if (control.CheckBoxes)
{
control.Items.OfType<SWF.ListViewItem>().ToList()
.ForEach(item => item.Checked = state);
}
else
{
control.Items.OfType<SWF.ListViewItem>().ToList()
.ForEach(item => item.Selected = state);
}
control.Refresh();
}
Going into debug mode all items are marked as selected.
Also at the control level SelectedItems is properly updated.
The issue is that visually the control just will not highlight the selected items like we have our WPF forms doing. As you can see in the code I also tried to refresh the control hoping that would show items selected, but no joy.
Has anyone solved this problem in getting selected items to display properly?
Thank!
Instead of using control.Refresh(), try control.Focus().

Windows form click event for panel does not work when another object is using it as a handle

I have an IC Image Control Grabber that is using a panel in a windows form as a handle (embedding the camera input in the form). I want to be able to click at some point on the panel and get the coordinates of the click in that panel. I have written that function and it works great before I embed the camera input. However, as soon as the camera is embedded the click event is not triggered when I click in the panel. Any ideas on what I can do to fix this problem?
Here is the documentation for the Grabber Object: (I call the setHWND() function)
http://www.imagingcontrol.com/en_US/support/documentation/class/Grabber.htm
Here is the relevant code I have written:
System::Void liveFeedPanel_Click(System::Object^ sender, System::EventArgs^ e)
{
System::Drawing::Point cursorPoint = liveFeedPanel->PointToClient(Cursor->Position);
//do something with that point
}
System::Void MainForm_Load(System::Object^ sender, System::EventArgs^ e)
{
HWND hwnd = static_cast<HWND>(this->liveFeePanel->Handle.ToPointer());
imageController->startCamera();
imageController->startLive(hwnd);
}
void ImageController::startLive(HWND hwnd)
{
if (grabber.isDevValid()) {
grabber.setHWND(hwnd);
grabber.setDefaultWindowPosition(false);
grabber.setWindowSize(//the new size);
grabber.startLive(true);
}
}
Thanks!
The solution I found was to use the MouseDown event instead of the Click event. This ignored what was being clicked on in the panel and simply looked at wether the mouse was within the panel.

How to delete items from a list in Windows Phone 8?

I have created an app. One of the features in the app is making a list and saving to Isolated Storage.
To the point, my problem is with deleting items from the list. To clarify, the user of the app can add items to list, and then save it. I am also using a LongListMultiSelector, which I downloaded from the web. What happens here is you can check items in a special boxes that pops-up (LongListMultiSelector feature). Up to this point, every feature works well. I want the user to be able to check the checkboxes, and press delete button, much like Windows Phone Hotmail, and rid of them. This is the part where I am having trouble.
So I click the trash can button which should function as a delete button. I have the following code for it.
private void button3_Click(object sender, EventArgs e)
{
while (LLMS.SelectedItems.Count > 0)
{
source.Remove((MainList)LLMS.SelectedItems[0]);
InitializeComponent();
}
}
LLMS represents the LongListMultiSelector.
MainList is class and the list.
What happens is the app freezes up and stops working, though no pop-up comes up.
You can use this lines of code:
void OnRemoveClick(object sender, EventArgs e)
{
IList source = MainList.ItemsSource as IList;
while (MainList.SelectedItems.Count > 0)
{
source.Remove((**ObjectName**)MainList.SelectedItems[0]);
}
}

How can I set a property for AutoMouseScroll and Mouse hower property to UltraDropdown?

I am using UltraDropDown control to bind a column of one UltraGrid control to list People category in list format.
This drop-down control have more than 25 items and show 8 categories Max, it's very fine. Now whenever I click on drop-down control to see all people category list then i have to hold scroll bar and drag down to see all categories. but I want to show all categories when I mouse scroll and its automatically move up and down to show all, and one more thing I want, when i mouse hover on listed categories then hover item should be shaded or colored.
Please help on both topic.
Thanks & Regards,
Shashi Bhushan Jaiswal
I believe that the first requirement is by default as behavior. Are you handling the MouseWheel event for this to not work?
Here is the code for your second requirement but I do not know if it is a good approach to use the MouseHover event as you like but this is your requirement:
void ultraDropDown1_MouseHover(object sender, EventArgs e)
{
if (cell != null && isInItem) {cell.Cell.Appearance.BackColor = Color.Red;}
}
CellUIElement cell;
bool isInItem = false;
private void ultraDropDown1_MouseEnterElement(object sender, Infragistics.Win.UIElementEventArgs e)
{
if (e.Element is EditorWithTextDisplayTextUIElement && e.Element.Parent.Parent is CellUIElement)
{
cell = (CellUIElement)e.Element.Parent.Parent;
isInItem = true;
}
else isInItem = false;
}

Windows Phone 7 Selection_Changed automatically

currently I'm developing an app for WP7 but came across a little problem with a Listbox event call Selection_Change. The problem is that when i return to the page that contains the listbox the selection_change event triggers without being changed at all or without any user input. The listbox code is similar to this:
private void lsbHistory_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int index = lsbHistory.SelectedIndex;
NavigationService.Navigate(new Uri("/Views/NextPage, UriKind.Relative));
}
On the page I navigate to, the only way out of the navigated page is by pressing back button or start button meaning that it will return to the page that contains the listbox. When I Navigate back the selection change triggers leading me sometimes to a exception. Has anyone been through this before?
Consider always checking if it's -1 (the default value).
private void lsbHistory_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int index = lsbHistory.SelectedIndex;
if (index != -1)
{
NavigationService.Navigate(new Uri("/Views/NextPage, UriKind.Relative));
lsbHistory.SelectedIndex = -1; // Set it to -1, to enable re-selection.
}
}
Also, you should consider wrapping the Navigate call in Dispatcher.BeginInvoke to have a better, more smooth, page transition.
The event will be fired when the list is populated.
The simplest solution for you will probably be to add a check that there is nothing selected before triggering your navigation:
if (lsbHistory.SelectedIndex > -1)
{
// do navigation
}
One thing to notice is that when you navigate back to the page which containt the ListBox, the ListBox still has the SelectedItem set to the value it had when the user navigated away. This means that lsbHistory.SelectedIndex will get the index of the item which was selected when the user navigated forward.
Maybe there's something in your code which presumes that the ListBox's SelectedItem is null when the user navigates to the page?

Resources