You would be taxed when you take the cash out or transfer them to another non RRSP/RESP account. If you sell them in your RRSP the gain is not taxed until you withdraw the cash.
If in your Investment account you would pay capital gains tax at your marginal rate and if in your TFSA you would pay no tax if an when you sell.
This is not tax advice just my understanding. Each of us has our own situation which can be very different depending on what your plans and accounts are so if you have a lot of shares talk with your tax guy or accountant and make sure you have a plan that you are good with